前言

本文应用的是mysql-8.0.26-winx64,解决思路是先让MySQL能够跳过明码验证,登陆后将明码批改成新的。

解决步骤

跳过验证将明码置空

【CMD窗口1】进行服务,而后前台启动服务并跳过验证。

# 进行服务net stop mysql# 前台启动服务并跳过验证mysqld --console  --skip-grant-tables --shared-memory

【CMD窗口2】登陆MySQL,将明码设置为空串

# 登陆MySQL,提醒输出明码回车跳过mysql -u root -p# 指定操作mysql库use mysql# 将root用户明码设置为空串update user set authentication_string = '' where user = 'root';# 登出MySQLexit

【CMD窗口1】按Ctrl+c进行服务

从新设置新密码

# 后盾启动MySQLnet start mysql# 明码是空了,提醒输出明码回车跳过mysql -u root -p# 明码批改成新的ALTER USER root@localhost IDENTIFIED  BY '123456';# 登出MySQLexit

验证

登陆MySQL,提醒明码间接回车会报错,因为设置了新密码,输出新密码即可登陆胜利。

mysql -u root -p