My friend forgot his mysql password and the database needs to be accessed by the root user. My friend is running MySQL 5.1 and as I browsed the MySQL manual the solution provided is not working though a slight change was made. Just like the provided step in the manual:
- Log on to your system as Administrator.
- Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it.If your server is not running as a service, you may need to use the Task Manager to force it to stop.
- Create a text file containing the following statements. Replace the password with the password that you want to use.UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; FLUSH PRIVILEGES;
FLUSHstatements each on a single line. The
UPDATEstatement resets the password for all
rootaccounts, and the
FLUSHstatement tells the server to reload the grant tables into memory so that it notices the password change.
- Save the file. For this example, the file will be named
- Open a console window to get to the command prompt: From the Start menu, select Run, then enter cmd as the command to be run.
- mysqld –init-file=C:\\mysql.txt
I used “mysqld –init-file=C:\\mysql.txt” instead of having mysql-nt which is the command provided on the manual. After the that you have now changed the root password. You can delete the mysql.txt file you created and you can now log in using the new account details.