Sunday, April 26, 2015

How to Recover MYSQL Root Password

Here, i will explain how can we recover mysql root password when we forget or else. I will explain to recover it by using simple steps as follows.
[root@linuxpathfinder ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
:: First of all use any one of the following command to stop the mysql service.
# service mysqld stop
(or)
# /etc/rc.d/init.d/mysqld stop
[root@linuxpathfinder ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]
:: After that start mysql service as following method.
[root@linuxpathfinder ~]# mysqld_safe –skip-grant-tables &
[1] 1564
[root@linuxpathfinder ~]# 121023 12:54:57 mysqld_safe Logging to ‘/var/log/mysqld.log’.
121023 12:54:58 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe method is mostly used and recommended way to start a mysqld server on Unix/Linux.
:: Now login without password into mysql root user
[root@linuxpathfinder ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.69 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
:: Now its time to update your password
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>
mysql> UPDATE user SET password=PASSWORD(“newrootpassword”) WHERE User=’root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
:: Now require restart service (stop and start) of mysql server.
[root@linuxpathfinder ~]# /etc/rc.d/init.d/mysqld stop
131023 13:11:39 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld:                                           [  OK  ]
[1]+  Done                    mysqld_safe –skip-grant-tables
[root@linuxpathfinder ~]# /etc/rc.d/init.d/mysqld start
Starting mysqld:                                           [  OK  ]
:: Access your mysql database with your recently created new password.
mysql -u root -p
Now above method to change mysql root password process has been completed. Please let me know if you follow any different way to recover lost mysql password.

No comments:

Post a Comment