Howto: How to Reset the MySQL Root Password

The following procedure can be used to reset the password for any MySQL root accounts on Linux and Unix (*nix). The instructions assume that you have got the proper permissions on the host system.

Stop the MySQL daemon process

sudo /etc/init.d/mysql stop

Create a text file /home/me/mysql.sql and place the following statements in it. Replace the password with the password that you want to use

UPDATE mysql.user SET Password=PASSWORD('a_new_password') WHERE User='root';

The UPDATE and FLUSH statements each must be written on a single line. The UPDATE statement resets the password for all existing root accounts, and the FLUSH statement tells the server to reload the grant tables into memory.

Start the MySQL server with the special --init-file option

mysqld_safe --init-file=/home/me/mysql.sql

Press Ctrl+C and then start the MySQL server again by /etc/init.d/mysql start and you are done.


blog comments powered by Disqus
Fork me on GitHub