一台电脑很久不用,拿起来要用黑箱进入本地数据库时,除了重新安装mysql外,也可用这种方法来修改本地mysql的密码,具体操作如下。
思路和基本操作来自于 本地Mysql忘记密码的修改方法(windows),感谢这位大佬
查询mysql的安装目录
![](https://img.haomeiwen.com/i14058594/a4cc62d6fe89681b.png)
![](https://img.haomeiwen.com/i14058594/3b88e11b911da7a7.png)
![](https://img.haomeiwen.com/i14058594/bec2ccb1579a130b.png)
![](https://img.haomeiwen.com/i14058594/06a9e505038c62e3.png)
![](https://img.haomeiwen.com/i14058594/becf2ba13b46fbaa.png)
![](https://img.haomeiwen.com/i14058594/aecf5ab8577ee736.png)
![](https://img.haomeiwen.com/i14058594/7032b29a71bb5234.png)
然后,win+R运行cmd后分别运行以下四行命令
mysql -u root -p #回车,这时让你输入密码,不输入,直接回车
use mysql
update user set authentication_string='' where user='root';
quit
![](https://img.haomeiwen.com/i14058594/a0b2702c109b2e4f.png)
接下来需要在mysql的bin目录下打开一个PowerShell命令窗口
net start mysql
mysql -u root -p #回车,不输入密码,回车
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
![](https://img.haomeiwen.com/i14058594/3a328a637692fe7d.png)
![](https://img.haomeiwen.com/i14058594/fc658250626cd6f6.png)
![](https://img.haomeiwen.com/i14058594/fc2d8624339cc77f.png)
网友评论