MySQL密码忘记了,怎么办?

1.停止数据库

[root@db01 ~]# systemctl stop mysqld

2.跳过授权表和网络启动

[root@db01 ~]# mysqld_safe --skip-grant-tables --skip-networking &

3.连接数据库 

[root@db01 ~]# mysql

4.刷新授权表

mysql> flush privileges;

5.修改密码

mysql> grant all on *.* to root@'localhost' identified by '111111' with grant option;

6.关闭后门

[root@db01 ~]# mysqladmin shutdown -uroot -p111111

7.正常启动数据库

[root@db01 ~]# systemctl start mysqld

8.进入 mysql

[root@db01 ~]# mysql -uroot -p111111
原文地址:https://www.cnblogs.com/chenlifan/p/13869295.html