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.
3. Now open notepad and paste following command in it.
UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
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.
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.
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.