1.登录su

 

2.vim /etc/mysql/my.cnf

* 有的版本在/etc/my.cnf

 

3.在[mysqld]下面添加skip-grant-tables,如果没有[mysqld],添加一行,保存退出。如下:

[mysqld]
skip-grant-tables

 

4.重启MySQL

systemctl restart mysql

 

5.进入MySQL

mysql

 

6.删除原密码,修改密码,退出

mysql>use mysql;
mysql>update user set authentication_string = '' where user = 'root';
mysql>alter user 'root'@'%' identified with mysql_native_password by '123456'; //其中123456是密码
mysql>flush privileges;
mysql>exit

 

7.删除上面增加到/etc/mysql/my.cnf文件中的skip-grant-tables

 

8.重启MySQL

systemctl restart mysql

 

相关文章:

  • 2021-08-03
  • 2021-11-28
  • 2021-11-29
  • 2021-07-05
  • 2021-09-17
  • 2021-11-07
  • 2022-12-23
猜你喜欢
  • 2021-11-20
  • 2022-12-23
  • 2021-09-27
  • 2021-06-08
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案