How to recover from a lost MySql root password

PDF

If you somehow lost the MySql root password it is possible to recover in just a few steps.

First stop the running MySql daemon process:

/etc/init.d/mysqld stop

Restart the MySql daemon to start with prompting for a password using mysqld_safe with the option skip-grant-tables:

mysqld_safe --skip-grant-tables &

Now you can connect to the MySql server without a password:

mysql --user=root mysql

At the MySql shell update the root user password followed by a flush of the privileges and logout of the MySql shell:

mysql> update user set password=password('NEWPASSWORD') where User='root';
mysql> flush privileges;
mysql> quit

Now stop the MySql daemon process again:

/etc/init.d/mysqld stop

Now we have set a new password for the root user we can start the MySql daemon with password restriction:

/etc/init.d/mysqld start

If you want to test your new password, connect to the MySql server as the root user with you new password:

mysql --user=root -p
Tags:
 

Please login first before adding a comment.

Search






You are here: Home Howtos and FAQs MySql How to recover from a lost MySql root password