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. With MySQL 8 add --shared-memory to the above cmd, for reasons why see https://bugs.mysql.com/bug.php?id=90554.

If the cmd generates an error, deal with the error then try again. Once it succeeds, mysqld hangs, which indicates the server is running.

Now open a second cmd window, and in it run

<MYSQL_HOME>\bin\mysql

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