一、准备mysql镜像源
到官网找mysql的yum源
wget https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
yum repolist all | grep mysql
如图:默认安装的是8.0。使用yum-config-manager --disable mysql80-community
取消mysql80-community的安装。然后yum-config-manager --enable mysql57-community
开启5.7安装。
二、安装mysql
yum install -y mysql-community-server
yum -y install mysql-devel
rm -rf /var/lib/mysql 如果之前安装过mysql执行
rm -rf /var/log/mysql.log 如果之前安装过mysql执行
systemctl restart mysqld
三、初始配置
1、修改root密码
grep "temporary password" /var/log/mysqld.log 查看默认密码
mysql -uroot -p
>=5.7.6版本使用
ALTER USER USER() IDENTIFIED BY \'pwd\'; 密码复杂要和规范,不建议降低密码复杂度策略,使用太简单的密码会报错
或者SET PASSWORD = "pwd"
低版本使用SET PASSWORD = PASSWORD(\'pwd\');
2、开启远程连接
grant all privileges on *.* to \'root\'@\'%\' identified by \'Mysql@password.123\';
flush privileges;