cd /usr/local/src
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-server-5.7.27-1.el7.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-client-5.7.27-1.el7.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-libs-5.7.27-1.el7.x86_64.rpm
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-common-5.7.27-1.el7.x86_64.rpm
yum remove mariadb-libs
yum install net-tools
yum install *.rpm
systemctl status mysqld.service
systemctl start mysqld.service
# 查看默认密码
grep 'temporary password' /var/log/mysqld.log
liykpntuu9?C
# 登陆后执行命令出现如下提示:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解决办法:使用初始密码登陆后需要修改root密码才行
alter user 'root'@'localhost' identified by '123liykpntuu9?C';
flush privileges;
然后退出重新登陆操作即可
# mysql5.6是密码为空直接进入数据库的,但是mysql5.7就需要初始密码
cat /var/log/mysqld.log | grep password
# 然后执行 mysql -uroot -p ,输入上面的到的密码进入,用该密码登录后,必须马上修改新的密码,不然会报如下错误:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
# 如果你想要设置一个简单的测试密码的话,比如设置为123456,会提示这个错误,报错的意思就是你的密码不符合要求
mysql> alter user 'root'@'localhost' identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
这个其实与validate_password_policy的值有关。
validate_password_policy有以下取值:
默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
有时候,只是为了自己测试,不想密码设置得那么复杂,譬如说,我只想设置root的密码为123456。
必须修改两个全局参数:
首先,修改validate_password_policy参数的值
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
validate_password_length(密码长度)参数默认为8,我们修改为1
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
# 完成之后再次执行修改密码语句即可成功
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)