Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pishangujeniya/0f839d11a7e692dadc49821c274a2394 to your computer and use it in GitHub Desktop.
Save pishangujeniya/0f839d11a7e692dadc49821c274a2394 to your computer and use it in GitHub Desktop.
Reset MySQL 8.0 root Password in Windows

Reset MySQL 8.0 root Password in Windows

  1. Stop the MySQL 8.0service from services
  2. Go to path C:\Program Files\MySQL\MySQL Server 8.0\bin and open cmd
  3. Run mysqld --console --skip-grant-tables --shared-memory
  4. Open new cmd in the same path
  5. Run following commands
  6. mysql -u root
  7. select authentication_string,host from mysql.user where user='root';
  8. UPDATE mysql.user SET authentication_string='' WHERE user='root';
  9. Now close both the cmd.
  10. Try to start the MySQL 8.0 service.
  11. Connect using username as root & password as blank.
  12. Change the password from the user managerment.
@llleixx
Copy link

llleixx commented Oct 18, 2023

Fails on mysql -u root with ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)

Don't close the previous cmd.

@pishangujeniya
Copy link
Author

Fails on mysql -u root with ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)

Don't close the previous cmd.

Refere this

@kotorkovsciy
Copy link

Thank you so much

@Senthilkumarvg
Copy link

Senthilkumarvg commented Jul 20, 2024

  1. Stop MySQL Service @ services.msc

  2. Create file change_mysql_pwd.txt with following content (replase YourNewPassword with desired new password you want to have for root user:

  3. ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewPassword';
    Save the file under C:\ change_mysql_pwd.txt

  4. Run CMD.exe as Admin (Start->Cmd->Right Click->Run as Administrator)

  5. Type in cmd: cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"

  6. Create “Data” Folder under "C:\Program Files\MySQL\MySQL Server 8.0\ (if already exists delete its contents!)

  7. Type in cmd: mysqld --install

  8. Type in cmd: mysqld --initialize

  9. Type in cmd: mysqld --init-file=C:\change_mysql_pwd.txt

  10. Login with root user account and the password set above.

  11. Delete C:\ change_mysql_pwd.txt file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment