1 以管理员身份打开cmd窗口,输入命令,停止MySQL服务
net stop mysql

2 开启跳过密码验证登录的MySQL服务
mysqld --console --skip-grant-tables --shared-memory
3 打开一个新的cmd窗口 在cmd里面输入mysql -u root -p就可以不用密码登录了,出现Enter PassWord: 直接回车进入
4 密码置为空后退出
use mysqlupdate user set authentication_string='' where user='root';

5 关闭以-console —skip-grant-tables —shared-memory 启动的MySQL服务cmd窗口
6 启动mysql服务 无密码状态登录mysql 最后修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';

