“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 :

3 Thoughts on “Reset MySQL Root Password in CentOS

  1. thank you sir, I followed about 8 tutorials and none worked so i this was the last one I’m going to try, if that didn’t work i was going to reinstall the OS, but it did work lol!!!

    but this didn’t work for me

    /etc/init.d/mysql start

    this worked for me 😀

    /etc/init.d/mysqld start

    • thanks Eli for pointing that out. I missed out the d on the commands. I corrected the post.

  2. luck_zone on April 19, 2012 at 9:48 pm said:

    I try to access database mysql. But it isn’t in mysql. So how can I change my password?
    Tks for your good attention.

Post Navigation