Reset the password on Windows environment

Sep 28, 2007 15:07 GMT  ·  By

One of the most disturbing and embarrassing situations is when you forget a password. And if that password is from your MySQL server, you are in big trouble. But every time there is a solution for every problem. You can set-up a new password using the following method.

In Windows environment, make sure you are logged in as Administrator. If you installed MySQL as services, stop it from Services manager,. You can find it in Control Panel -> Administrative Tools -> Services. If you didn't install it as services, kill it from Task Manager. Next you will have to create a text document where you will insert SET PASSWORD FOR 'root'@'localhost' = PASSWORD('NewPassword'); , save the document with any name (I recommend you to use mysql_new_password.txt).

Next, open command prompt and execute the following command: C:> C:mysql inmysqld --init-file=C:mysql_new_password.txt. The command from the text document is executed after --init-file option. When you will start the server, the command from C:mysql_new_password.txt is executed and this will reset the password. Another thing that you should know is that if you installed MySQL using MySQL Installation Wizard you must specify another option: --defaults-file. So, the command will be:

C:> "C:/Program Files/MySQL/MySQL Server 5.1/bin/mysqld.exe" --defaults-file="C:/Program Files/MySQL/MySQL Server 5.1/my.ini" --init-file=C:/mysql_new_password.txt

If you don't know the setting for --defaults-file, you can find it in Services Manager: Control Panel -> Administrative Tools -> Services. From there look for MySQL service, right-click on it, choose properties and in Path to executable you will find the setting for --defaults-file.

The final step is to restart the MySQL server from the Service Manager (if you installed MySQL as service) or use the restart command from the command prompt. From now, you can login using the new password.

This is the solution for the problem. There is another solution which is the simplest possible: don't forget your passwords. :)