Saturday, May 26, 2007

Reset lost root password for MySQL

 

If the server is not already running, start it up without checking for user credentials.

If your MySQL bin directory is not your system search path, change your working directory to the bin directory.

Start the MySQL process with skip-grant-tables option.

>mysqld-nt.exe --skip-grant-tables

Now MySQL is started  with every user having Full access all tables.

Now get to the admin console with user set to root .

>mysql --user=root

Then type  >use mysql  to select the mysql database.

You can combine the two steps by using   >mysql --user=root mysql

The user credentials are in the user table in mysql database.

Now set the new password by updating the user table.

>update user set Password=PASSWORD('new-password') where user='root';

Get MySQL to reload the grants table.

>flush privileges;

[If you are going to restart the server anyway, flushing might not be necessary as the user credentials and privileges are loaded on start up]

exit the mysql admin console .

>exit

To stop the server use the following command.

>mysqladmin shutdown

No comments:

Post a Comment