How to Reset Forgotten MySQL Root Password

Overview

Often times we accidentally changed the root password of our mysql, this can be caused by some scripts that we used for any automation process.

Procedure

1. Login as root to the database server.
2. Stop the mysql daemon or service.
3 Start the mysql daemon and skip the grant tables which store the passwords.

mysqld_safe –skip-grant-tables

4. You should see mysqld start up successfully and you should be able to connect to mysql without a password.

mysql –user=root mysql

5. Update the mysql password by running:

mysql> update user set Password=PASSWORD(‘new-password’) where user=’root’;
mysql> flush privileges;
mysql> exit;

Now kill your running mysqld, then restart it normally. You should be good to go.

Spread the love

Leave a Reply

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