mysql忘记root密码

1,service mysql stop       # mysql5.1版本的服务名是 mysqld,而mysql5.6版本的二进制包的服务名是 mysql.

2, /etc/init.d/mysql start  --skip-grant-tables

3,mysql

>  此时就可以在mysql里面修改root密码了

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

4,/etc/init.d/mysql stop 

5, mysql -uroot -p123456     # ------> 此时就可以进入到MySQL了。

mysql>  

mysql> grant all privileges on *.* to root@'localhost' identified by '123456';    #这条命令在 --skip-grant-tables状态下修改不了密码表。
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it ca
mysql>

原文地址:https://www.cnblogs.com/kaishirenshi/p/9155604.html