Category Archives: Database

Resetting MySQL root password on Windows

Recently i got the nice task to reset the root password for a MySQL server running on Windows. As i know from Linux some time ago i thought i could use the mysqld_safe trick, but the binary was not existing under windows.

So i tried several howtos on google but nothing worked. When i started mysqld.exe on the command line without any options all was fine. But then the default mysql.ini was used and so the database was empty because he could not find the mysql data dir.

So after some time i found the solution for me, sticking together pieces from every how-to on the web.

  1. Stop the MySQL server using “Windows services” or task manager
  2. Create a textfile (C:\mysql-init.txt) that is executed on MySQL server startup, example content:
    UPDATE mysql.user SET Password=PASSWORD('1234') WHERE User='root';
    FLUSH PRIVILEGES;
  3. Start the MySQL server using following command (Please adjust to your path and settings):
    "C:/Programme/MySQL/MySQL Server 5.6/bin\mysqld" --defaults-file="C:\Dokumente und Einstellungen\All Users\Anwendungsdaten\MySQL\MySQL Server 5.6\my.ini" --init-file=C:\\mysql-init.txt
  4. The “root” password is reset now. You can now stop the manual started MySQL server (task-manager) and start again the service. You can login now using your new password.

The “trick” here is to use the right parameter order. I tried first to use the “–init-file” Parameter before the “–defaults-file” parameter, but that didnt worked. I dont know if this is a specific windows problem, maybe someone knows?