1.跳过登录mysql的验证

vi /etc/my.cnf

在[mysqld]段中加入

skip-grant-tables

保存并退出

linux忘记mysql5.7的root用户密码


2.重启服务

service mysqld restart

3.修改密码并清除缓存

mysql -uroot -p

密码直接回车就好

use mysql;

update user set authentication_string=password("your password") where user="root";

这里修改密码用了authentication_string字段,如果是比较低的版本,把这个字段改成password就可以了

flush privileges;

4.将my.cnf修改为未改动前

vi /etc/my.cnf

去掉skip-grant-tables,保存并退出

重启服务即可

service mysqld restart


相关文章:

  • 2022-01-19
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2021-08-13
  • 2021-11-21
  • 2022-12-23
猜你喜欢
  • 2021-04-01
  • 2021-05-22
  • 2022-01-29
  • 2021-06-05
  • 2021-12-16
相关资源
相似解决方案