Recovering and Changing Your MySQL Root Password



Recovering and Changing Your MySQL Root Password

Sometimes you may have to recover the MySQL root password because it was either forgotten or misplaced. The steps you need are:

1.
Stop MySQL:

     [root@bigboy tmp]# service mysqld stop
     Stopping MySQL:  [ OK   ]
     [root@bigboy tmp]#

2.
Start MySQL in Safe mode with the safe_mysqld command and tell it not to read the grant tables with all the MySQL database passwords:

     [root@bigboy tmp]# safe_mysqld --skip-grant-tables &
     [1] 4815
     [root@bigboy tmp]# Starting mysqld daemon with databases from
     /var/lib/mysql
     [root@bigboy tmp]#

3.
Use the mysqladmin command to reset the root password. In this case, you are setting it to ack33nsaltf1sh:

     [root@bigboy tmp]# mysqladmin -u root flush-privileges \
       password "ack33nsaltf1sh"
     [root@bigboy tmp]#

4.
Restart MySQL normally:

     [root@bigboy tmp]# service mysqld restart
     Stopping MySQL: 040517 09:39:38 mysqld ended
     [ OK   ]
     Starting MySQL: [ OK   ]
     [1]+ Done                     safe_mysqld --skip-grant-tables
     [root@bigboy tmp]#

The MySQL root user will now be able to manage MySQL using this new password.