How to Reset Forgotten MySQL Root Password

First things first. Log in as root and stop the mysql daemon. Now lets start up the mysql daemon and skip the grant tables which store the passwords.

#mysqld_safe –skip-grant-tables

You should see mysqld start up successfully. If not, well you have bigger issues. Now you should be able to connect to mysql without a password.

#mysql –user=root mysql

Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2 to server version: 5.0.22

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

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

Now stop your running mysqld, then restart it normally. You should be good to go. Try not to forget your password again.

 

Leave a Reply

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

CAPTCHA *