MySQL超级管理员忘记密码

--skip-grant-tables:跳过授权表
--skip-networking :跳过TCP/IP连接

关闭数据库

service mysqld stop

使用安全模式启动

mysqld_safe --skip-grant-tables --skip-networking &
或者:意外发现
service mysqld restart --skip-grant-tables --skip-networking 

登录数据库并修改密码

[root@db01 ~]# mysql
mysql> alter user root@'localhost' identified by '123';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> 
mysql> flush privileges;   #手工加载授权表
mysql> alter user root@'localhost' identified by '123';

重启数据库到正常模式

[root@db01 ~]# service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 

猜你喜欢

转载自www.cnblogs.com/Mercury-linux/p/12319307.html