1、安装MySQL源
# 下载mysql安装包
[root@VM-8-12-centos local]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# 安装源
[root@VM-8-12-centos ~]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
2、yum安装mysql (需要一点时间)
[root@VM-8-12-centos ~]# yum -y install mysql-community-server
3、启动mysql服务
[root@VM-8-12-centos ~]# systemctl start mysqld
4、设置开机启动
[root@VM-8-12-centos ~]# systemctl enable mysqld
[root@VM-8-12-centos ~]# systemctl daemon-reload
5、修改root登录密码
mysql安装完成后,/var/log/mysqld.log文件中生成一个默认root临时密码
[root@VM-8-12-centos ~]# vim /var/log/mysqld.log
使用这个密码登录mysql
修改root密码,并设置远程登录
# 修改root密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '5gHQn82jw$Ijs@kU';
Query OK, 0 rows affected (0.00 sec)
# 设置远程登录
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '5gHQn82jw$Ijs@kU' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
6、重启mysql
[root@VM-8-12-centos ~]# systemctl restart mysqld
7、测试远程登录