Centos下mysql8忘记root密码的解决办法

首先,打开配置文件/etc/my.cnf,在末尾添加一行:

skip-grant-tables

然后重启mysql服务:

service mysqld restart

然后可以直接登录到mysql,在终端下输入mysql即可进入到mysql终端中。

依次输入如下命令:

use mysql;

select host, user, authentication_string, plugin from user;

此时应该可以看到在用户名为root的记录里面,authentication_string字段是有一串字符的,就是root的密码加密后的字符串。先把它清空:

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

再修改密码:

alter user 'root'@'%' identified by '你的新密码';

这里要注意的是,mysql8中对于这个密码的要求提高了,必须是同时包含大小写字母、数字、特殊符号

posted @ 2019-06-01 11:07  东围居士  阅读(1035)  评论(0编辑  收藏  举报