mysql忘记root密码

1、停止数据库

service mysql stop

2、修改my.cnf

利用vim命令打开mysql配置文件my.cnf

在mysqld进程配置文件中添加skip-grant-tables,添加完成后,执行wd保存。

3、启动mysql

servicee mysql start

4、进入数据库

mysql -u root -p    输入密码的时候直接回车

5、修改密码

update mysql.user  set password=password('newpassword') where user='root';

flush privileges;

quit;

6、注释掉my.cnf 

skip-grant-tables 改为 #skip-grant-tables

7、重启mysql

service mysql restart;

原文地址:https://www.cnblogs.com/changfengSven/p/6137528.html