For Linux and Shell scripting.

How to reset MySQL root password?


If you forgot root password for your MySQL server, you can follow the steps below to reset it.

1. Login to the server as root and stop MySQL service.

# /etc/init.d/mysqld stop

2. Start mysqld_safe service.

# mysqld_safe –skip-grant-tables &

3. Login to MySQL server now. It won’t ask you for a password.

# mysql -u root

4. Set up a new MySQL root user password:

mysql> use mysql;

mysql> update user set password=PASSWORD(“NEW-ROOT-PASSWORD”) where User=’root‘;

mysql> flush privileges;

mysql> quit

5. Restart your MySQL service.

# /etc/init.d/mysqld restart

6. Try to login using new password. It should work fine.

# mysql -u root -p

That’s it !!!


4 thoughts on “How to reset MySQL root password?

  1. Good one…
    copying to my blog… 🙂

  2. how does this help if we don’t even know the root password?

    • when you start mysql in safe mode (with –skip-grant-tables), it won’t ask you for the root password when you access mysql.

      If you mean that you forgot system’s root password, you can reboot the system in single user mode which will let you into the root account without asking the root credentials. You can reset the password then.

  3. Hi,

    Excellent.Nice knowledge sharing. Thanks for same.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s