系统:centos 7
版本:mysql 5.7
1、停止服务
systemctl stop mysqld
2、开启MySql免密码登录
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
3、启动服务
systemctl start mysqld
4、免密码登录
mysql -u root
5、设置新密码
UPDATE mysql.user SET authentication_string = PASSWORD('xxxxxx') WHERE User = 'root' AND Host = 'localhost';
6、刷新权限&新密码生效
FLUSH PRIVILEGES;
7、再次停止服务
systemctl stop mysqld
8、关闭MySql免密码登录
systemctl unset-environment MYSQLD_OPTS
9、再次启动服务
systemctl start mysqld
10:可以愉快的使用新密码登录了
mysql -u root -p