Thursday, 18 September 2014

How to reset mysql root password in linux

If you forgot your mysql root password, not able to login to your mysql database. Don't worry this is the simplest way I could find to reset mysql root user password.

1. Stop MySQL Service


[root@manoj ~]# /etc/init.d/mysqld stop

2. Execute Following Command


[root@manoj ~]# mysqld_safe --skip-grant-tables and Press ENTER

3. Now Let’s Login to MySQL Without Password

[root@manoj ~]# mysql -u root

4. Use Following Queries to Reset your MySQL root Password

mysql> use mysql; 

mysql> update user set password=PASSWORD(“NEW-MYSQL-ROOT-PASSWORD”) where User=’root'; 

mysql> flush privileges; 

mysql> quit 

5. Let’s Stop MySQL Server as we have started in Step 2

[root@manoj ~]# service mysqld stop 

6. Now Start MySQL Service

[root@manoj ~]# service mysqld start 

7. Execute Following Command to Login with New Password 

[root@manoj ~]# mysql -u root -p 

You should now be able to connect to MySQL as root using the new password.

No comments:

Post a Comment