1.下载mysql源安装包
2.安装mysql源
$ yum localinstall mysql57-community-release-el7-8.noarch.rpm
3.检查mysql源是否安装成功
$ yum repolist enabled | grep "mysql.*-community.*"
4.修改yum源 【可跳过】
$ vim /etc/yum.repos.d/mysql-community.repo
改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。
备注:enabled=1表示即将要安装的mysql版本,这个文件也可以不修改,默认安装mysql最高版本
![](https://images2018.cnblogs.com/blog/1443749/201808/1443749-20180802095051183-2053425212.png)
5.安装MySQL
这一步才是真正安装mysql
$ yum install mysql-community-server
6.启动MySQL服务并设置开机启动
$ systemctl start mysqld
$ systemctl enable mysqld
$ systemctl daemon-reload
7.端口开放
$ firewall-cmd --zone=public --add-port=3306/tcp --permanent
$ firewall-cmd --reload8.修改root本地登录密码
1)查看mysql密码
$ grep 'temporary password' /var/log/mysqld.log
![](https://images2018.cnblogs.com/blog/1443749/201808/1443749-20180802094841902-1212339549.png)
$ mysql -uroot -p
3)修改密码【注意:后面的分号一定要跟上】
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或者:
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
mysql> show variables like '%password%';
![](https://img2018.cnblogs.com/blog/1443749/201908/1443749-20190811003430801-863534851.png)
9.添加远程登录用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'caoxiaobo'@'%' IDENTIFIED BY 'Caoxiaobo0917!' WITH GRANT OPTION;
10.使用客户端连接测试
备注:这里的用户名是第9步设置的caoxiaobo,密码为:Caoxiaobo0917!
![](https://img2018.cnblogs.com/blog/1443749/201908/1443749-20190811004311863-1655097189.png)
![](https://img2018.cnblogs.com/blog/1443749/201908/1443749-20190811004539206-1135637622.png)