Methods To Recover Lost MySQL Root Password On Linux And Windows

By | October 16, 2009

Methods To Recover Lost MySQL Root Password On Linux And Windows

In some conditions we need recover MySQL root password. Following are the steps used on Windows and Linux for recovering the root password.

Recover MySQL root password on Linux

Under Linux we can accomplish the recovery using six steps. You need to be on root login to perform the following steps,

1. Stop MySQL server service.

# /etc/init.d/mysqld stop

2. Start MySQL server without password.

# mysqld_safe --skip-grant-tables &

3. Login into mysql client prompt.

# mysql -u root

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 3

Server version: 5.0.77 Source distribution

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql>

4. Set up new MySQL root password.

mysql> use mysql; mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root'; mysql> flush privileges; mysql> quit

5. Stop Mysql Server

# /etc/init.d/mysqld stop

6. Start MySQL server and login as root.

# /etc/init.d/mysqld start

# mysql -u root -p

Recover MySQL root password on Windows Systems

Under Windows we can accomplish the recovery using eight steps. Following are the steps,

1. Stop MySQL server service.

Go to Start->Run->services.msc ,Stop MySQL server services.

2. Navigate into MySQL bin folder located inside the MySQL installation path.

Go to Start->Run->cmd

Use “cd” command to change the directory.

cd C:MySQLbin

3. Execute the following command from “C:MySQLbin” command prompt.

mysqld.exe -u root --skip-grant-tables

4. Leave the current MS-DOS console as it and open a new MS-DOS console.

Go to Start->Run->cmd

Use “cd” command to change the directory.

cd C:MySQLbin

5. Enter mysql.exe and Enter

mysql>

6. Set up new MySQL root password.

mysql> use mysql; mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root'; mysql> flush privileges; mysql> quit

7. Close all MS-DOS console and start MySQL server.

Go to Start->Run->services.msc ,Start MySQL server services.

8. Login into MySQL prompt.

Steps would be different according the MySQL installation.

Cheers!

Melbin Mathew

www.talk2melbin.com

Melbin Mathew

I am Melbin Mathew, Systems Engineer from Kerala, India. I live with my parents, daughter and my wonderful wife. I graduated in 2004 with a bachelor’s degree in Electronics and Hardware from Mahatma Gandhi University, Kottayam and completed certification in MCITP, RHCE, CCNA, VCP ...Read More
Category: Linux Windows

About Melbin Mathew

I am Melbin Mathew, Systems Engineer from Kerala, India. I live with my parents, daughter and my wonderful wife. I graduated in 2004 with a bachelor’s degree in Electronics and Hardware from Mahatma Gandhi University, Kottayam and completed certification in MCITP, RHCE, CCNA, VCP ...Read More

  • SHAIJU

    i m using redhat linux and i do the above..but still its showing
    ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
    when i trying login
    pls..pls help me

    • http://www.talk2melbin.com Melbin Mathew

      Hi Shaiju,

      After stopping mysql server, type the following command on the terminal “mysqld_safe –skip-grant-tables &” (use – – in front of skip) . Then try to login into mysql server.

      Thanks
      Melbin Mathew