Lost MySQL password in Windows

from the Artful MySQL Tips List

If the MySQL service has started, stop it. Open a "DOS" cmd window, and in it run ...

<MYSQL_HOME>\mysqld --defaults-file="<MYSQL_HOME>\my.ini" --console --skip-grant-tables

where is the full path to the MySQL installation folder. If this generates an error, deal with the error then try again.

When the above cmd succeeds, mysqld hangs. The server is running.

Open a second cmd window, and in it run


There execute ...

select host, user, password from mysql.user;

Edit the entries to suit, delete any rows with a blank user value, then issue ...

Flush Privileges;

Exit mysql, then run ...

mysqladmin shutdown

Switch to the cmd window where you started the server, and run ...

<MYSQL_HOME>\mysqld --defaults-file="<MYSQL_HOME>\my.ini" --console

Now in the 2nd cmd window run ...

<MYSQL_HOME>\bin\mysql -uUSR -pPWD

where USR & PWD are user & password values you just created or edited. If one of those values is still wrong, repeat the whole sequence from the top.

Return to the Artful MySQL Tips page