How to Reset the MySQL Root Password

If you’ve forgotten your MySQL root password, resetting it is straightforward. Follow these steps carefully:

Step 1: Stop the MySQL Service

Before making changes, stop the MySQL service to prevent conflicts.

  • Linux (Systemd-based systems):
    sudo systemctl stop mysql
  • Windows:
    1. Open the Services app.
    2. Find the MySQL service.
    3. Right-click and select Stop.

Step 2: Start MySQL in Safe Mode

Start MySQL without loading the privilege tables, allowing unrestricted access.

  • Linux:
    sudo mysqld_safe –skip-grant-tables &
  • Windows: Open a terminal and navigate to the MySQL bin directory (e.g., C:\Program Files\MySQL\MySQL Server 8.0\bin) and run:
    mysqld –skip-grant-tables

Step 3: Log in Without a Password

Connect to the MySQL server:
mysql -u root

Step 4: Update the Root Password

Run the following commands to reset the password:

  1. Use the mysql database: USE mysql;
  2. Update the password (replace new_password with your desired password):

    • MySQL 5.7 and later: ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘new_password’;

    • MySQL 5.6 and earlier: SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘new_password’);

  3. Flush privileges: FLUSH PRIVILEGES;

  4. Exit MySQL: EXIT;

Step 5: Restart MySQL Normally

Stop the safe mode instance and restart the service normally.

  • Linux: sudo systemctl restart mysql
  • Windows:

    1. Open the Services app.
    2. Find the MySQL service.
    3. Right-click and select Start.

Step 6: Test the New Password

Verify the new password by logging in:
mysql -u root -p

Enter your new password when prompted.

By following these steps, you can reset your MySQL root password and regain access to your database.

Read Also: How to Customize the version of MySQL database in cPanel

Popular Posts You May Read

Explore more hosting insights, tips and industry updates.

How to Run a Ping Test in Windows, Mac OS, and Linux

How to Run a Ping Test in Windows, Mac OS, and Linux

Running a ping test is one of the easiest ways to check whether your system…

How to Clear Cache in Laravel Applications

In this article, we will explain how to clear the cache in Laravel Applications. Talking…

Secure Your Database Server in 10 Simple Ways

It may be the health records or your credit card details; everything is stored in…