Reset Forgotten MySql root Password Under Windows

~ 1 minute

If you forgot root password for your MySQL database server running under Microsoft Windows, there is still a way to access your database and even reset your password using the command prompt.

Follow next steps:

 

1. Stop your MySQL server completely. This can be done from Wamp(if you use it), or start “services.msc” using Run window, and stop the service there.

2. Open your MS-DOS command prompt using “cmd” inside the Run window. Then go to your MySQL bin folder, such as C:\MySQL\bin. Path is different if you use Wamp.

3. Execute the following command in the command prompt:

  mysqld.exe -u root --skip-grant-tables

4. Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.

5. Go to your MySQL bin folder again.

6. Enter “mysql” and press enter.

7. You should now have the MySQL command prompt working. Type “use mysql;” so that we switch to the “mysql” database.

8. Execute the following command to update the password:

UPDATE user SET Password = PASSWORD('your_new_passowrd') WHERE User = 'root';

However, you can now run almost any SQL command that you wish.

After you are finished close the first command prompt, and type “exit;” in the second command prompt.

 

You can now start the MySQL service. That’s it.

 


If you liked the post, we should get connected - follow me on Twitter

70 Comments Reset Forgotten MySql root Password Under Windows

  1. Cookie

    I don’t know how old this post is but I just wanted to say thanks.

    This method worked when two other methods didn’t.

    Reply
      1. Karthi M

        Hi Jole,

        I am getting this

        ERROR 2003 (HY000): Can’t connect to MySQL server on ‘localhost’ (10061)

        while executing 6th step

        Reply
  2. krishna

    you gave me life by saving my time.thanks man. great work. very simple straight fwd explanation love u man.
    friendly
    krishna

    Reply
  3. Neo

    If you still have access to the DB via gui (in my case I had access to the DB via HeidiSql), please make sure you flush your privileges (e.g. FLUSH PRIVILEGES;) after you run your update statement.

    Thank you for this great post!

    Reply
  4. Pingback: Locked yourself out of MySQL: reset the root password | Miraz Al-Mamun

  5. Archana

    This worked!! I have been trying to get my lost password reset for some time now and nothing seem to work. I can’t thank you enough..

    Reply
  6. Pingback: Reset Forgotten MySql root Password Under Windows | PHP DEVELOPER ZONE

  7. Ana

    This really worked! But I had to run the MS-DOS Command Prompt as administrator… Is that because I’m using Windows 8.1?

    Reply
  8. Bube

    OMG I was searching maybe for 2 hours trying to find something that will work and after doing this method It REALLY WORKED!!! THANKS MAN!

    Reply
  9. Tom

    Finally, you are the tenth website I have visited and yours is the only one who easily helped me fix it. I don’t know where I’d be if I had lost my database. Thank a million!

    Reply
  10. Patrick

    OMG THIS FIXED MYSQL AND MY LOVE LIFE!!! Thanks!!! Actually I strongly emphasize adding a FLUSH PRIVILEGES; statement after the password update as someone else recommended in the post.

    Reply
  11. Karthi M

    Hi Jole,

    It is not working for me while executing 6th step :

    ERROR 2003 (HY000): Can’t connect to MySQL server on ‘localhost’ (10061)

    Reply
  12. Sajjad

    If you have root access to the server where mysql is running you should stop the mysql server using this command

    sudo service mysql stop

    Now start mysql using this command

    sudo /usr/sbin/mysqld –skip-grant-tables –skip-networking &

    Now you can login to mysql using

    sudo mysql
    FLUSH PRIVILEGES;
    SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘MyNewPass’);

    Full instructions can be found here http://www.techmatterz.com/recover-mysql-root-password/

    Reply
  13. Paul S

    Hi,
    Just great – I had used as MYSQL generated password & managed to lock myself out?OUCH. These instructions are exact and clear. I’m back in.
    Thank you very much.

    Reply
  14. Calvin

    This been a good tutorial, especially on my end. I will be going to follow those instructions you had just explain on my Windows whenever it happened the same thing.

    Reply
  15. Pingback: MariaDB Root Issue | Echo4Golf Clear

Leave a Reply

Your email address will not be published. Required fields are marked *