Reset Root Password in MySQL on Windows

See SQL: Tips and Tricks for similar articles.

Forgetting your MySQL root password can be scary, but thankfully there is a way to reset it. These instructions are based on the documentation here.

  1. Exit out of the MySQL Installer and any MySQL Tools (e.g., MySQL Workbench).
  2. Stop the MySQL service if it’s running:
    1. stop mysql service step 1
    2. stop mysql service step 2
  3. Directly on your C drive, create a file named mysql-init.txt with the following contents (but choose your own password):
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
  4. Open a command prompt: open command prompt windows
  5. In the command prompt, you will enter the following commands (see screenshot below. Yours may be white text on a black background):
    1. Change directory to the main MySQL directory:
      cd "C:\Program Files\MySQL\"
    2. Get a directory listing to make sure that MySQL Server is in there:
    3. Change directory into the MySQL Server directory. This may be a little different for you if you have a different version of MySQL Server:
      cd "MySQL Server 8.0"
    4. Change directory again into the bin directory:
      cd bin
    5. Run the script in the text file that you created in step 3:
      mysqld --init-file=C:\\mysql-init.txt
    All the above steps are shown in the following screenshot: mysql change root pw steps

This should restart MySQL with your new password. If it works correctly, you can then open MySQL Workbench and log in to localhost on MySQL.

If it does not work, try some of the suggestions at the bottom of documentation page.

Written by Nat Dunn. Follow Nat on Twitter.

Related Articles

  1. Reset Root Password in MySQL on Windows (this article)
  2. How to Create an ER Diagram for a MySQL Database with Free Tools
  3. How to Round Up in SQL
  4. How to Concatenate Strings in SQL
  5. How to Select All Columns in a Row in SQL
  6. How to Check Multiple Conditions in SQL
  7. How Work with White Space and Semicolons in Simple SQL Selects
  8. How to Sort Records in SQL
  9. How to Write Subqueries (Simple and Correlated)