Recover MySQL root Password in RHEL/CentOS

We can recover  MySQL database server password with the following steps.

1.Stop the MySQL service by using below command.

service mysqld stop
/etc/init.d/mysqld stop

stopservice

2.Now Start the MySQL server without password by using

 mysqld_safe --skip-grant-tables & 

stopmysqlsafe

3.Now Connect to mysql using mysql -u root  command

mysqluser

4. Now Set a new MySQL root user password by typing below commands in command prompt.

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

restpassword2

5.Now stop mysql service

stopservice

6.Now start the mysql service using service mysqld start or /etc/init.d/myqld start and try to connect to mysql using mysql -u root -p with new password.

Advertisements
This entry was posted in Linux, Mysql. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s