Saturday 6 February 2016

How to Recover MySQL database server password

Step 1: Stop Mysql Server: 

[root@linuxcnf~]# /etc/init.d/mysqld stop
Stopping MySQL database server: mysqld.

Step 2: Start to MySQL server w/o password:

[root@linuxcnf~]# mysqld_safe --skip-grant-tables &
[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[4256]: started

Step 3: Connect to Mysql server using mysql client:

[root@linuxcnf ~]#  mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.6.10-Centos_1-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

Step 4: Setup new Mysql root user Password:

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

Step 5: Stop MySQL Server:

[root@linuxcnf ~]#  /etc/init.d/mysqld stop
Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/
mysqld_safe[6186]: ended
[1]+  Done                    mysqld_safe --skip-grant-tables

Step 6: Start Mysql server and check:

[root@linuxcnf ~]#  /etc/init.d/mysqld start
[root@linuxcnf ~]#  mysql -u root -p

No comments:

Post a Comment