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.
- Exit out of the MySQL Installer and any MySQL Tools (e.g., MySQL Workbench).
- Stop the MySQL service if it’s running:
- 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';
- Open a command prompt:
- In the command prompt, you will enter the following commands (see screenshot below. Yours may be white text on a black background):
- Change directory to the main MySQL directory:
cd "C:\Program Files\MySQL\"
- Get a directory listing to make sure that MySQL Server is in there:
dir
- 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"
- Change directory again into the bin directory:
cd bin
- Run the script in the text file that you created in step 3:
mysqld --init-file=C:\\mysql-init.txt
- Change directory to the main MySQL directory:
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.
Related Articles
- Reset Root Password in MySQL on Windows (this article)
- How to Create an ER Diagram for a MySQL Database with Free Tools
- How to Round Up in SQL
- How to Concatenate Strings in SQL
- How to Select All Columns in a Row in SQL
- How to Check Multiple Conditions in SQL
- How Work with White Space and Semicolons in Simple SQL Selects
- How to Sort Records in SQL
- How to Write Subqueries (Simple and Correlated)