1、停止mysql服务

$ service mysql stop

2、修改my.cnf文件

# 修改my.cnf文件,在文件新增 skip-grant-tables,在启动mysql时不启动grant-tables,授权表
$ sudo vim /etc/mysql/my.cnf
[mysqld]
skip-grant-tables

3、启动mysql服务

service mysql restart

4.清空密码

use mysql;
update user set authentication_string='' where user='root';

5.注释掉skip-grant-tables后重启mysql

service mysql restart

6.设置新密码

update user set plugin='mysql_native_password' where user='root'; #更改加密方式
alter user 'root'@'localhost' IDENTIFIED BY '123456';#设置密码
FLUSH PRIVILEGES;

然后就可以密码登录了,

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐