本教程本人通过网上查找,自己总结的,亲测没得问题;

方法一:通过初始密码

找回安装是的初始密码:

1
grep 'temporary password' /var/log/mysqld.log

方法二:使用操作系统

使用操作系统账号和密码,进行修改密码

1
2
3
4
5
1、mysql -uroot -p

2、输入你的centos的密码

3、UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword') WHERE User = 'root' AND Host = 'localhost';

注:如果显示 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,说明你的密码不符合安全要求,

1
4、FLUSH PRIVILEGES;
1
5、quit;

方法三:强制进行修改密码

1
2
3
4
5
6
7
8
9
1、systemctl stop mysqld

2、systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

3、systemctl start mysqld

4、mysql -u root

5、UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword') WHERE User = 'root' AND Host = 'localhost';

注:如果显示 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,说明你的密码不符合安全要求,

1
2
3
6、FLUSH PRIVILEGES;

7、quit;