用管理员身份关闭MySQL服务。
命令为:net stop mysql
![](https://img-blog.csdnimg.cn/img_convert/ae7c4fa8ac6078011af42a2426175bec.png)
在MySQL目录中,找到my.ini文件
![](https://img-blog.csdnimg.cn/img_convert/a3f48204ae19d4b4d4dd102114e2df16.png)
新增一行配置,用于跳过登录安全检查: skip-grant-tables
![](https://img-blog.csdnimg.cn/img_convert/a62e7b023c5ed121beab0cffc57f356c.png)
管理员重启MySQL服务
命令为:net start mysql
![](https://img-blog.csdnimg.cn/img_convert/ebcf99dc8b35b91286bd39cb0258c7b1.png)
按win+r,输入cmd回车,登录
![](https://img-blog.csdnimg.cn/img_convert/54c4be63aa474419371ea1647ed84d6f.png)
双击回车,即可进入MySQL
![](https://img-blog.csdnimg.cn/img_convert/6ed10b7bea200ecbc9b7e63a2e70283c.png)
修改root用户密码:
4.1输入命令:use mysql;
4.2改密码password('XXXX') (XXXX为你想设置的密码):
update user set authentication_string=password('root') where user='root' and host='localhost';
4.3刷新权限:flush privileges;
![](https://img-blog.csdnimg.cn/img_convert/21ed42768c62ee7c8bb57fce060593a2.png)
注释掉my.ini文件中的刚写入的配置
![](https://img-blog.csdnimg.cn/img_convert/b919e29b25c877870b9767a53da444db.png)
以管理员身份重启MySQL服务
![](https://img-blog.csdnimg.cn/img_convert/e75d44fb4978d6b6482387175e659247.png)
登录MySQL,输入新设置的密码即可
![](https://img-blog.csdnimg.cn/img_convert/5e0f577db08efa51046f3fc17357fb12.png)