Password
MySQL8 Forgot Password Solution under CentOS #
CentOS下MySQL8忘记密码的解决方法
在 skip-grant-tables 模式下启动 MySQL,该模式下启动 MySQL 时不启动授权表功能, 可以直接免密码登录。 1.修改 /etc/my.cnf 在 [mysqld] 区域添加配置,设置免密登录:
skip-grant-tables
2.重启 MySQL 服务
systemctl restart mysqld
3. 命令行输入 mysql 直接登录 MySQL:
mysql
4.修改 root 密码为空:
update mysql.user set authentication_string='' where User='root';
flush privileges;
5.将 /etc/my.cnf 中的 skip-grant-tables 去掉,重启 MySQL 服务:
systemctl restart mysqld
6.再次登录 MySQL,密码为空,修改 root 密码为新密码:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'xxxxxx';
flush privileges;