MySQL 超级管理员密码忘记了,怎么处理

--skip-grant-tables    :跳过授权表
--skip-networking      :跳过TCP/IP连接
[root@master1 ~]# pkill mysqld
[root@master1 ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 
[root@master1 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@master1 ~]# systemctl start mysqld --skip-grant-tables
systemctl: unrecognized option --skip-grant-tables
[root@master1 ~]# service mysqld start --skip-grant-tables
Starting MySQL. SUCCESS! 
[root@master1 ~]# mysql

(1)关闭数据库

[root@master1 ~]# systemctl stop mysqld

(2)使用安全模式启动

[root@master1 ~]# mysqld_safe --skip-grant-tables --skip-networking &
或者
[root@master1 ~]# service mysqld start --skip-grant-tables --skip-networking

(3)登录数据库并修改密码

 

[root@master1 ~]# mysql

mysql> alter user root@localhost identified by mysql;
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 mysql;

 

(4)重启数据库到正常模式

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

MySQL 超级管理员密码忘记了,怎么处理

上一篇:MySQL查询时间常用函数


下一篇:腾讯大佬总结的代码重构原则,看完再也不怕面试官问啦!