How to Reset the Root Password in MySQL

For those who have had the annoyance of losing their root password in MySQL, or  will loose it yet, here’s a tip which can save the day.

Stop or kill the MySQL service

# killall mysqld    or    # service mysqld stop

Start MySQL in safe mode:

# mysqld_safe –skip-grant-tables &

log in using the mysql client:

# mysql

Access the MySQL database

> use mysql;

Setting new MySQL root password:

> update user set password = password (‘type your new password here’) where user = ‘root’ and host = ‘localhost’;

Reload privileges by typing:

> flush privileges;

Exit MySQL:

> quit

Restart MySQL  in normal mode:

# service mysqld stop

And finally, let’s start with the new MySQL root password:

# service mysqld start

And voila, your new root password and access granted to the database again.

Leave a Reply

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