How to Reset MySQL Root Password on Windows When Forgotten


2 views

When you lose access to your MySQL root account, you'll need to use the --skip-grant-tables option to bypass authentication. This method works for all MySQL versions (5.7, 8.0+) on Windows systems.

First, stop the MySQL service:

net stop MySQL

Then start MySQL in safe mode with privilege bypass:

mysqld --skip-grant-tables --shared-memory

Open another command prompt and connect to MySQL:

mysql -u root

For MySQL 5.7:

UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root';
FLUSH PRIVILEGES;

For MySQL 8.0+:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
FLUSH PRIVILEGES;

Exit MySQL and restart the service normally:

net stop MySQL
net start MySQL
  • If you get "Access denied" errors, ensure you've stopped all MySQL processes first
  • For Windows services, check that you're running commands as Administrator
  • If using MySQL Installer, you may need to use the configuration wizard instead

After resetting:

mysql_secure_installation

This will guide you through securing your MySQL installation, including removing anonymous users and test databases.


Every DBA has been there - you inherit an old MySQL server or simply forget the root password. While reinstalling MySQL might seem like the nuclear option, there's a cleaner way to reset credentials without losing your databases.

  1. Stop the MySQL service:
    net stop MySQL
  2. Create a temporary init file (reset.txt) containing:
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
  3. Start MySQL in safe mode with skip-grant-tables:
    mysqld --init-file=C:\\reset.txt --skip-grant-tables --console
  4. In a new terminal, verify the new password:
    mysql -u root -pNewPassword

For MySQL 5.7+ installed via the official installer:

# Generate random temporary password
mysqld --initialize --console

# Note the temporary password shown
# Login and immediately change it:
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewSecurePass123!';
  • Always use complex passwords (12+ chars, mixed case, special chars)
  • Consider creating limited-privilege admin accounts instead of using root
  • Document credentials in a secure password manager

Error 1045: If you still can't login:

# Check if another MySQL instance is running
tasklist | findstr "mysqld"

# Verify your MySQL data directory location
mysqld --verbose --help | findstr "datadir"