How to reset MySQL root password?

To reset the MySQL root password, you can follow these steps:

  1. Stop the MySQL Service:
    First, you need to stop the MySQL service. You can do this using the following command:

    sudo systemctl stop mysql
  2. Start MySQL in Safe Mode:
    Start MySQL in safe mode with the --skip-grant-tables option, which allows you to access the database without a password:

    sudo mysqld_safe --skip-grant-tables &
  3. Log in to MySQL:
    Open a new terminal and log in to MySQL as the root user:

    mysql -u root
  4. Reset the Password:
    Once you are in the MySQL shell, run the following commands to reset the root password. Replace new_password with your desired password:

    FLUSH PRIVILEGES;
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
  5. Exit MySQL:
    Exit the MySQL shell:

    EXIT;
  6. Stop Safe Mode:
    Stop the MySQL safe mode process. You may need to find the process ID (PID) and kill it, or simply restart the MySQL service:

    sudo systemctl stop mysql
  7. Start MySQL Normally:
    Start the MySQL service normally:

    sudo systemctl start mysql
  8. Log in with the New Password:
    Now you can log in to MySQL with the new root password:

    mysql -u root -p

You will be prompted to enter the new password you set.

0 Comments

no data
Be the first to share your comment!