A2oz

How to Get MySQL Root Password in Windows?

Published in Database Administration 2 mins read

You can retrieve the MySQL root password in Windows using the following methods:

1. Check the Configuration File

  • Open the my.ini file located in the MySQL installation directory.
  • Search for the password parameter under the [mysqld] section.
  • If the password is set, it will be displayed in plain text.

2. Use the MySQL Command Line

  • Open a command prompt as administrator.
  • Navigate to the MySQL installation directory (e.g., C:\Program Files\MySQL\MySQL Server 8.0\bin).
  • Run the following command:
     mysqld --skip-grant-tables
  • Open a new command prompt and connect to the MySQL server with the following command:
     mysql -u root
  • Once connected, you can change the root password using the SET PASSWORD command. For example:
     SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
  • Remember to restart the MySQL server after changing the password.

3. Reset the Root Password

  • If you have lost your MySQL root password, you can reset it by following these steps:
    • Stop the MySQL service.
    • Open a command prompt as administrator and navigate to the MySQL installation directory.
    • Run the following command to reset the password:
       mysqld --skip-grant-tables --initialize-insecure
    • Start the MySQL service.
    • You can now connect to MySQL with the default password (empty).
    • Change the password using the SET PASSWORD command as described above.

Note: For security reasons, it is highly recommended to use a strong and unique password for your MySQL root account.

Related Articles