Linux CentOS 下找回MYSQL的Root密码

1.编辑配置文件

vi /etc/my.cnf

2.在[mysqld]中添加:

skip-grant-tables

Eg.
[mysqld]
skip-grant-tables
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

3.重启Mysql

service mysqld restart

4.无密码登陆和选择数据库

mysql
use mysql;

5.修改密码:

update user set password=password('新密码') where user='root';

6.执行并退出

flush privileges;
quit;

7.重新编辑 /etc/my.cnf 删除 skip-grant-tables

8.重启Mysql

service mysqld restart

 

THE END