解决方法:
修改vim /etc/yum.repos.d/mysql-community.repo 源文件
[mysql57-community] name=MySQL 5.7 Community Server ## baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/ baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
sudo yum install mysql-community-server
sudo yum -y remove mysql*
sudo systemctl start mysqld #启动mysql sudo systemctl status mysqld #查看mysql状态
实际上,第一次启动后,mysql5.7 会生成一个随机root密码,并放到了 /var/log/mysqld.log 这个日志里。
grep 'password' /var/log/mysqld.log
ALTER USER USER() IDENTIFIED BY '123456';
注意:直接修改密码时,可能会报错:Your password does not satisfy the current policy requirements。这是你设置的密码不符合要求。默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。如果非要设置为这种简单密码,则可以修改密码策略后在修改:
set global validate_password_policy=0; set global validate_password_length=1;
grant all privileges on *.* to root@'%' identified by '123456'; flush privileges;