How to Change MySQL root Password in Windows

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.

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.

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

How to Change MySQL root Password in Windows

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

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.

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

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

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”

This path will vary depending upon where you have installed 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.

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!

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

1 thought on “How to Change MySQL root Password in Windows”

  1. hi
    when I run the command (in my case):
    “C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe” –defaults-file=”C:\ProgramData\MySQL\MySQL Server 8.0\my.ini” –init-file=”C:\mysql-init.txt”

    my cmd prompt change to a dash and waiting mode and I don’t get any response!!

    and when I press Ctrl+C it quites from halt mode

    please help me.
    thank you.

Leave a Comment

Your email address will not be published. Required fields are marked *