🔑

Resetting MySQL Root Password Guide

Sep 13, 2024

Notes on Resetting MySQL Root Password on Windows

Overview

This lecture discusses the steps required to reset the MySQL root password in a Windows operating system, specifically for MySQL Workbench.

Steps to Reset MySQL Root Password

Step 1: Stop MySQL Service

  • Search for services in Windows.
  • Locate MySQL (e.g., MySQL 8.0) in the services list.
  • Right-click and stop the service.

Step 2: Create a Command File

  • Open any location (e.g., Desktop) and create a new folder.

  • Inside the folder, create a text file (e.g., password.txt).

  • Write the following command in the text file:

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
    • Replace new_password with the desired password (e.g., 12345).
  • Save the file.

Step 3: Run MySQL with the Command File

  • Open File Explorer and navigate to the MySQL installation directory, typically found in:
    C:\Program Files\MySQL\MySQL Server 8.0\bin

  • Copy this bin directory path.

  • Open Command Prompt as Administrator.

  • Change directory to the copied path by entering:

    cd C:\Program Files\MySQL\MySQL Server 8.0\bin
  • Locate the Program Data folder (may be hidden).

    • To view hidden items, go to View > Hidden items.
    • Navigate to:
      C:\ProgramData\MySQL\MySQL Server 8.0
  • Find and execute the command in the Command Prompt:

    mysqld --default-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --init-file="C:\path\to\your\password.txt"
    • Replace C:\path\to\your\password.txt with the actual path to the created file.

Step 4: Restart MySQL Service

  • After running the command, restart the MySQL service from the services menu.

Step 5: Verify New Password

  • Open MySQL Workbench or Command Line.
  • Attempt to log in using the new password (e.g., 12345).
  • If you encounter an error, ensure that the MySQL service is running.

Conclusion

  • Successfully resetting the MySQL root password involves stopping the service, creating a command file, executing it in command prompt, and verifying the new password.
  • If there are any issues, students are encouraged to reach out in the comments.