如何在Windows中更改MySQL根密码

We may forget MySQL root password when we use it after long time. It is a very common problem among programmers. Few days back I also faced the same problem and luckily I found its solution by searching on internet. I thought that I should share the solution to help other programmers. So below I have given the step by step guide for this.

长时间使用后,我们可能会忘记MySQL的root密码。 这是程序员之间非常普遍的问题。 几天前,我也遇到了同样的问题,幸运的是,我通过在互联网上搜索找到了解决方案。 我认为我应该分享解决方案以帮助其他程序员。 因此,下面我给出了逐步的指导。

如何在Windows中更改MySQL根密码 (How to Change MySQL root Password in Windows)

1. First of all you need to stop MySQL server. For this, go to Control Panel > Administrative Tools > Services. Scroll down to get the MySQL service.

1.首先,您需要停止MySQL服务器。 为此,请转到控制面板>管理工具>服务 。 向下滚动以获取MySQL服务。

2. Right click on it and then click on Stop option to stop the server.

2.右键单击它,然后单击“ 停止”选项以停止服务器。

How to Change MySQL root Password in Windows

3. Now open notepad and paste following command in it.

3.现在打开记事本,并在其中粘贴以下命令。

UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
FLUSH PRIVILEGES;

Replace newpassword with the password you want to change. Now save it as text file with name mysql-init.txt.

newpassword替换为要更改的密码。 现在将其另存为名为mysql-init.txt的文本文件。

4. After this again go to Control Panel > Administrative Tools > Services, right click on MySQL service and click on Properties option.

4.之后,再次转到控制面板>管理工具>服务 ,右键单击MySQL服务,然后单击属性选项。

5. Copy the MySQL executable path as shown in below image.

5.复制MySQL可执行文件路径,如下图所示。

How to Change MySQL root Password in Windows

For example in my case the path is:

例如,在我的情况下,路径为:

“D:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld” –defaults-file=”D:\ProgramData\MySQL\MySQL Server 5.6\my.ini”

“ D:\ Program Files \ MySQL \ MySQL Server 5.6 \ bin \ mysqld” –defaults-file =“ D:\ ProgramData \ MySQL \ MySQL Server 5.6 \ my.ini”

This path will vary depending upon where you have installed MySQL.

根据安装MySQL的位置,此路径将有所不同。

6. Now open command prompt or cmd and paste the path that you have just copied. After that give a space and type –init-file= and then inside double quotes type the path of the mysql-init.txt file that you created in previous steps. See below screenshot as an example.

6.现在打开命令提示符或cmd,然后粘贴刚刚复制的路径。 之后,提供一个空格并键入–init-file = ,然后在双引号中键入您在先前步骤中创建的mysql-init.txt文件的路径。 请参见下面的屏幕截图作为示例。

How to Change MySQL root Password in Windows

Tip: Right click on text file and then click Properties option. There you can get its path or location, just copy it and use in above step.

提示:右键单击文本文件,然后单击“属性”选项。 在那里,您可以获取其路径或位置,只需复制它并在上面的步骤中使用即可。

7. Finally restart your computer. You have done!

7.最后,重新启动计算机。 你做完了!

If you are getting any difficulty to change MySQL root password in windows then feel free to ask your queries by commenting below.

如果您在Windows中更改MySQL根密码遇到任何困难,请随时通过以下评论提出疑问。

翻译自: https://www.thecrazyprogrammer.com/2015/11/how-to-change-mysql-root-password-in-windows.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值