MySQL忘记密码/重置密码

1.登录su

 

2.vim /etc/mysql/my.cnf

* 有的版本在/etc/my.cnf

 

3.在[mysqld]下面添加skip-grant-tables,如果没有[mysqld],添加一行,保存退出。如下:

[mysqld]
skip-grant-tables

 

4.重启MySQL

systemctl restart mysql

 

5.进入MySQL

mysql

 

6.删除原密码,修改密码,退出

mysql>use mysql;
mysql>update user set authentication_string = '' where user = 'root';
mysql>alter user 'root'@'%' identified with mysql_native_password by '123456'; //其中123456是密码
mysql>flush privileges;
mysql>exit

 

7.删除上面增加到/etc/mysql/my.cnf文件中的skip-grant-tables

 

8.重启MySQL

systemctl restart mysql

 

posted @ 2021-05-06 20:20  Clotho_Lee  阅读(81)  评论(0)    收藏  举报