Reset MySQL 5.1 Root password

Sometimes you might want to reset your used password since it is used for long time.

To reset MySQL database password, you may need to consider different Operating System and it’s version will have minor differences during the root password reset.

Today, Mick Genie will guide you how to reset MySQL database v5.1  through Windows Operating System and Linux Operating System.

For Windows Operating System,
1. Firstly, create a text file and name it as resetpassword.txt and you may save it to C drive.
2. Enter the following word to your text file.

UPDATE mysql.user SET Password=PASSWORD('M!ckGen1e@Malays1a') WHERE User='root';
FLUSH PRIVILEGES;

Where you should replace M!ckGen1e@Malays1a with your new password.
3. Stop your MySQL services as step below.
Run -> services.msc -> MySQL -> Stop
4. Open Command Prompt(cmd) and run the command as below to start the MySQL services.

C:\mysql\bin\mysqld.exe --init-file=C:\\resetpassword.txt

5. Delete the file named resetpassword.txt.

For Linux Operating System,
1. Stop the MySQL services.

service mysql stop

2. Save the following  command as a text file name resetpassword to anywhere such as /home/resetpassword.txt.

UPDATE mysql.user SET Password=PASSWORD('M!ckGen1e@Malays1a') WHERE User='root';FLUSH PRIVILEGES;

Where you should replace M!ckGen1e@Malays1a with your new password.
3. Run the following command to start the MySQL services.

mysqld_safe --init-file=/home/resetpassword &

4. Delete the file named resetpassword.

Reset your  MySQL while login to MySQL console.
1. Log into your console at first.
2. Run the following command and set the password as your preferable password.

mysql> UPDATE mysql.user SET Password=PASSWORD('M!ckGen1e@Malays1a') WHERE User='root';
mysql> FLUSH PRIVILEGES;

Published by

Mick Genie

Mick Genie is the founder of MickGenie.com and working at ExaBytes Network Sdn Bhd and WPWebHost web host company. He is expertise in Windows and Linux environment especially web hosting related information, tips and trick as well as the IT Information.

5 thoughts on “Reset MySQL 5.1 Root password”

  1. Mick
    Thanks for the help to reset the password. Unfortunately when I reboot my machine the access denied on root local host message appears again. So I have to reset the password again. I am running on windows 7 if that makes a difference.

    Thanks Eugene

Comments are closed.