MySQL Reset Root Password

mysql services

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:

  1. Log on to your system as Administrator.
  2. 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.
  3. 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;

    Write the UPDATE and FLUSH statements each on a single line. The UPDATE statement resets the password for allroot accounts, and the FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.

  4. Save the file. For this example, the file will be named C:\mysql.txt.
  5. 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.
  6. mysqld –init-file=C:\\mysql.txt

mysql reset password

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.

mysql reset root password

Did find the post very useful? Maybe you want to buy me a glass of beer!