Ubuntu系统忘记mysql root密码

1. 停止mysql服务

service mysql stop

2. 修改my.cnf文件

sudo find / -name my.cnf
sudo vim /etc/mysql/my.cnf

添加如下内容:

[mysqld]
skip-grant-tables

3. 启动mysql服务

service mysql restart

4. 更改mysql root用户密码

mysql
use mysql;
update user set authentication_string='password' where user='root';
quit;

5. 再次修改my.cnf文件

sudo vim /etc/mysql/my.cnf

将之前添加的内容注释掉

6. 再次重启mysql

service mysql restart
mysql -u root -p

参考资料: https://blog.csdn.net/luckytanggu/article/details/80251833

posted @ 2022-07-03 17:24  tiansz  阅读(340)  评论(0编辑  收藏  举报