Recover root Password for MySQL

Torbjorn Zetterlund ThunderBear
0

You can recover MySQL database server password with following five easy steps.

Step # 1: Stop the MySQL server process.

Step # 2: Start the MySQL (mysqld) server/daemon process with the –skip-grant-tables option so that it will not prompt for password.

Step # 3: Connect to mysql server as the root user.

Step # 4: Setup new mysql root account password i.e. reset mysql password.

Step # 5: Exit and restart the MySQL server.

Here are commands you need to type for each step (login as the root user):

Step # 1 :  Stop mysql service

# /etc/init.d/mysql stop
Output:

Stopping MySQL database server: mysqld.

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

# mysqld_safe --skip-grant-tables &
Output:

[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started

Step # 3: Connect to mysql server using mysql client:

# mysql -u root
Output:

Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>

Step # 4:  Setup new MySQL root user password

mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';<br style="padding: 0px; margin: 0px;" />mysql> flush privileges;<br style="padding: 0px; margin: 0px;" />mysql> quit</code></p>
<h3 style="margin-top: 1.833em; margin-bottom: 0.611em; margin-left: 0px; font-weight: normal; font-size: 1.286em; line-height: 22px; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;">Step # 5: Stop MySQL Server:</h3>
<p style="margin-top: 0px; margin-bottom: 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 14px; line-height: 22px;"><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; display: block; background-position: 0px 0px; background-repeat: repeat repeat; border-width: 1px; border-color: #dddddd; border-style: solid;"># /etc/init.d/mysql stop</code><br style="padding: 0px; margin: 0px;" />Output:</p>
<pre style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; clear: both; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; line-height: 1.5em; color: #111111; border-width: 1px; border-color: #dddddd; border-style: solid;">Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended
[1]+ Done mysqld_safe --skip-grant-tables</pre>
<h3 style="margin-top: 1.833em; margin-bottom: 0.611em; margin-left: 0px; font-weight: normal; font-size: 1.286em; line-height: 22px; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;">Step # 6:  <a href="http://www.cyberciti.biz/faq/how-do-i-access-mysql-server-from-the-shell-prompt-command-line/" style="text-decoration: underline; color: #2361a1;">Start MySQL server and test it</a></h3>
<p style="margin-top: 0px; margin-bottom: 1.571em; color: #111111; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 14px; line-height: 22px;"><code style="padding-top: 0.667em; padding-right: 0.917em; padding-bottom: 0.667em; padding-left: 0.917em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.833em; margin-left: 0px; line-height: 1.5em; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, 'Andale Mono', Monaco, Courier, 'Courier New', Verdana, sans-serif; font-size: 0.857em; overflow-x: auto; overflow-y: auto; display: block; background-position: 0px 0px; background-repeat: repeat repeat; border-width: 1px; border-color: #dddddd; border-style: solid;"># /etc/init.d/mysql start<br style="padding: 0px; margin: 0px;" /># mysql -u root -p</code></p>'

Leave a Reply