Reset MySQL Root Password in CentOS

Posted on July 21, 2010 · Posted in Blog, Linux, MySQL

“Senior moments” tends to occur more frequently these days. Sign that I’m getting old. And several times already, I forgot the root password of my MySQL installation.

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


Step # 1: Stop the MySQL server process.

# /etc/init.d/mysqld stop

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

# mysqld_safe --skip-grant-tables &

Step # 3: Connect to mysql server as the root user.
# mysql -u root
Step # 4: Setup new mysql root account password.

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

Step # 5: Exit and restart the MySQL server.
# /etc/init.d/mysqld stop

Step # 6: Start MySQL server and test it
# /etc/init.d/mysqld start
# mysql -u root -p

The steps are basically the same when resetting the password in other linux flavors. I’m using the same steps in Ubuntu but with a slight difference in shell commands.

reference :
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html