码迷,mamicode.com
首页 > 数据库 > 详细

mysql8.0.22忘记密码和重置

时间:2021-02-22 12:44:28      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:mysql8   system   password   nbsp   重启   salt   步骤   art   info   

步骤1、修改mysql配置文件

[root@localhost ~]# vi /etc/my.cnf

在底部添加一行

skip-grant-tables

保存退出

重启mysql

[root@localhost ~]# systemctl restart mysqld

步骤2、将root密码置空

[root@localhost ~]# mysql -uroot -p

直接回车

mysql> use mysql

mysql> select host, user, authentication_string, plugin from user;

mysql> update user set authentication_string=‘‘ where user=‘root‘;

mysql> \q

步骤3、改回mysql配置文件

返回步骤1,将添加的一行删或注释掉,保存退出,重启mysql.

[root@localhost ~]# vi /etc/my.cnf

#skip-grant-tables

[root@localhost ~]# systemctl restart mysqld

步骤4、修改root密码

[root@localhost ~]# mysql -uroot -p

直接回车

mysql> ALTER USER ‘root‘@‘%‘ IDENTIFIED BY ‘MyNewPass4!‘;

mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
qH%eL3@wUvYXiOmjuqkVggHwIwYIWZA3.0kpC1HjNaGWxM7EH51cB | caching_sha2_password |
| %         | userbook         | *59B1E18AA534B3A2E3A33430582E9EE06AF3B729                              | mysql_native_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
5 rows in set (0.00 sec)

这时会出现如下显示格式不正确的情况。

(思路:

可通过先将%设置为localhost,

再执行,

mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘MyNewPass4!‘;

将localhost设置为%,

mysql> update user set host=‘%‘ where user=‘root‘;

然后,

mysql> flush privileges;

解决。)

 

mysql8.0.22忘记密码和重置

标签:mysql8   system   password   nbsp   重启   salt   步骤   art   info   

原文地址:https://www.cnblogs.com/wtsgtc/p/14426480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!