CentOS6.10忘记MySQL8密码的解决办法
1.首先,打开配置文件/etc/my.cnf,在末尾添加一行:
skip-grant-tables
2.然后重启mysql服务:
service mysqld restart
3.然后可以直接登录到mysql,在终端下输入mysql即可进入到mysql终端中。
4.依次输入如下命令:
use mysql;
select host, user, authentication_string, plugin from user;
5.此时应该可以看到在用户名为root的记录里面,authentication_string字段是有一串字符的,就是root的密码加密后的字符串。先把它清空:
update user set authentication_string='' where user='root';
6.然后我们打开配置文件/etc/my.cnf,去掉刚刚的skip-grant-tables。
7.输入以下命令flush privilege。
mysql> flush privilege;
6.再修改密码(%是我的情况,有的可能是localhost,请参照步骤4中的查询结果):
alter user 'root'@'%' identified by '你的新密码';
注意!MySQL8对密码的验证要求提高了,必须包含大小写和特殊字符。

浙公网安备 33010602011771号