mysql数据库管理员密码忘记或者丢失,如何破?

mysql数据库管理员密码忘记或者丢失,如何破?
1. 停止数据库 
[root@db01 data]# systemctl stop mysqld
2. 使用维护模式启动数据库 
[root@db01 data]# mysqld_safe --skip-grant-tables --skip-networking &   
3. 无密码登录并修改密码 
mysql  mysql> alter user root@'localhost' identified  by '123456'; 
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement 
mysql> flush privileges;     # 手工加载授权表 
mysql> alter user root@'localhost' identified  by '123456'; 
4. 重启数据库到正常模式
[root@db01 data]# systemctl restart mysqld

这样就可以用刚刚设置的新密码登录数据库啦!!!

 

posted @ 2021-11-25 14:44  菜鸟儿~  阅读(77)  评论(0编辑  收藏  举报