Mysql 忘记 root 密码解决方法

Linux 版本:Centos 7.8

Mysql 版本:5.7.17


1. 修改配置文件 vi /etc/my.cnf,添加 skip-grant-tables

[mysqld]
skip-grant-tables

2. 重启 mysql

systemctl restart mysqld

3. 使用 root 登录 (密码为空),并修改密码

use mysql;
update mysql.user set authentication_string=password('password') where user='root';
flush privileges;

4. 修改配置文件 vi /etc/my.cnf,移除 skip-grant-tables

5. 重启 mysql

systemctl restart mysqld

猜你喜欢

转载自blog.csdn.net/fan63182830/article/details/121166451