Mysql 忘记root密码解决方法
--skip-grant-tables #跳过授权表
--skip-networking #跳过远程登录
1.关闭数据库
2.mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
或者修改/etc/my.cnf增加这两个参数
3.登录数据库update mysql.user表
mysql> select user,host,authentication_string from mysql.user;
+---------------+-----------+-------------------------------------------+
| user | host | authentication_string |
+---------------+-----------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+---------------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
mysql> alter user root@'localhost' identified by '123';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user root@'localhost' identified by '123';
Query OK, 0 rows affected (0.00 sec)
4.关闭数据库
5.重启数据库
如果修改的my.cnf,则修改root密码后,一定要将my.cnf去掉参数--skip-grant-tables --skip-networking