linux重置mysql的root密码

1.vim /etc/my.cnf  ;在[mysqld]下添加一行 skip-grant-tables

2.service mysqld restart ;重启服务

3.mysql -u root -p ;随便输入密码进入

4.update mysql.user set password=password("输入新的密码") where user="root"; 

mysql5.7以后:

update mysql.user set authentication_string=password("输入新的密码") where user="root"; 

重置密码;

5.MySQL> flush privileges;
  MySQL> exit

刷新配置,退出;

6.vim /etc/my.cnf ;还原

7,重启服务,新密码访问了就;

当你发现自己的才华撑不起野心时,就请安静下来学习吧!
原文地址:https://www.cnblogs.com/longchuqianyuan/p/14894074.html