Resetting a MySQL Root Password in Windows

Security Lock Image

It happens to even the most attentive database person. Maybe an employee quit. Maybe a hacker got in. Somehow you now have a MySQL database running in Windows and you do NOT know what the root password is.

How do you fix this?

First off, don’t panic. Know that many, many other people have been here. You can get through this.

You’ll need physical / remote desktop access to the server for this to work. Hopefully that can be arranged for you.

From the windows start menu, look for SERVICES and run it. In the SERVICES list, find the entry for MySQL. On my machine it’s called “MySQL80”. Stop that from running.

While you’re in there, RIGHT-click on that entry to get its properties. In the ‘path to executable’, make note of the defaults-file value.

Next up, you’ll want to create a new text file (I use Notepad) that has this line:

ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘***INSERTPASSWORDHERE***’;

Of course, change the password to what you want to use.

Save that in your C: directory. I give it the name mysql-init.txt for clarity.

Now, to run the command.

Search for the CMD utility and RUN IT AS AN ADMINISTRATOR. On my version of windows I get to this by RIGHT clicking on the CMD program. This gives you the access to change the root password.

Move to the correct directory. In my case I type:

cd “C:\Program Files\MySQL\MySQL Server 8.0\bin”

Now we’re in the right place. Type:

mysqld –defaults-file=”C:\ProgramData\MySQL\MySQL Server 8.0\***DEFAULTSFILEHERE**” –init-file=C:\mysql-init.txt

Of course, make sure to change the defaults file value to what you got from your personal defaults file.

Run that! Restart the service.

Then make sure you can log into MySQL with your NEW password.

Finally, delete the text file in the C directory.

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.