忘记 MySQL 密码

1、编辑 mysql 的配置文件 /etc/my.cnf ,在 [mysqld] 下添加以下内容。

skip-grant-tables

2、重启 MySQL 服务。

service mysql restart

3、不使用密码直接登录 MySQL。

mysql

4、切换到 mysql 库,修改账户密码,然后退出。

use mysql;
update user set password=PASSWORD("new_pass") where user='root';
quit;

 

5、注释配置文件中的 skip-grant-tables ,重启MySQL服务器。

 

posted @ 2020-10-03 23:07  Astral  阅读(80)  评论(0编辑  收藏  举报