首先打开cmd
找到mysql 解压位置进去bin 文件夹
前提是你的mysql本地服务要关闭
输入指令
mysqld --console --skip-grant-tables --shared-memory
可以手动关闭
以管理员身份运行
打开后找到mysql
停止服务
然后
从新打开cmd窗口同样进入mysql 的bin目录下
输入
mysql -uroot -p
直接回车然后会让你输密码,不用输密码直接回车
然后就连接成功
输入指令修改新密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
如果报错这种错
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option
就执行下面的指令
flush privileges;
然后在执行
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
```bash
在这里插入代码片