Recover MySQL root password

By | 2011-04-02

It happens from time to time. For me, it happens after being on a long vacation. I forget my password, and the root password. Shame on me. Recovering is simpler than you think!

  1. Open console and stop mysql service
    #/etc/init.d/mysqld stop
  2. Then i run this service without password
    #mysqld_safe --skip-grant-tables
    You can also run it as a background if you would not use another console (shell)
    #mysqld_safe --skip-grant-tables &
  3. Then i open another console and connect to mysql
    #mysql -u root output mysql>
  4. Next, i setup new password for root user
    mysql> use mysql;
    mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
    mysql> flush privileges;
    mysql> quit
  5. Last step is stop mysql service
    #/etc/init.d/mysqld stop
  6. Finish, and start mysqld and test new password
    #/etc/init.d/mysqld start #mysql -u root -p
Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.