centos mysql忘记密码

1.停止mysql 服务:service mysqld stop;

2.vim命令打开mysql配置文件my.cnf(位置一般为:/etc/my.cnf)

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

4.重新打开mysql服务:service mysqld stop;

5.登陆mysql:mysql -u root -p; 不用输入密码登录mysql;

6.update user  set password=password('newpassword') where user='root' (5.7以前版本)

  update user  set authentication_string=password('newpassword') where user='root' (5.7及以后版本)

 

7.在mysqld进程配置文件中注释skip-grant-tables,添加完成后保存

 

8.重启mysql服务

posted @ 2016-03-26 12:24  北方乐逍遥  阅读(205)  评论(0编辑  收藏  举报