MySQL 5.5 command line client forget password in Windows 7

shiva picture shiva · Sep 8, 2012 · Viewed 19.5k times · Source

I forgot the root password for MySQL 5.5 command line client in Windows 7. I am unable to login. How can I retrieve the password or reset?

Answer

ibtarek picture ibtarek · Sep 8, 2012

RTM : http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

Here's a step by step procedure :

Important : you need to have system administrator privileges on windows.

1- Stop your MySQL server

2- Create an empty text file, and put these statements in :

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;

You may replace the string 'MyNewPass' by your own password.

3- Save the text file. (eg. c:\temps\mysql-reset-pass.sql )

4- Restart MySQL server and tell it to load the file :

mysqld-nt --console --init-file=c:\temps\mysql-reset-pass.sql

Depending on your MySQL installation, you may also need to give the path to your ini file. In this case, add the "--defaults-file" switch

mysqld-nt --console --init-file=c:\temps\mysql-reset-pass.sql --defaults-file=c:\path\to\my.ini

5- Restart the server normally. You should be able to connect using your new password

Remembrer to delete the text file that you've just created in step 2. It contains the password in clear text.