How to reset MySQL 8.0 root password on Centos 7.x? Print

  • 0

You may need to reset your MySQL root password if you lost or forget it. MySQL stores the existing password to the user table. To update the same password, we need to bypass the MySQL authentication. 

Please refer to the following steps to reset MySQL root password using -skip-grant-tables.

  1. Log in to your server using SSH.

  2. Stop the MySQL service using the below command.

    # systemctl stop mysqld.service
  3. Run the below command to bypass MySQL authentication.

    # mysqld --skip-grant-tables --user=mysql &
  4. Log in to MySQL now and it will not ask for the password.

    # mysql -u root
  5. Reload all the grants using the below commands.

  6. Run the below query to modify the root password. Ensure that you change the new_password with your updated password.

    # ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_passowrd';
  7. Stop and start the MySQL service with the below command.

    # systemctl stop mysqld.service# systemctl start mysqld.service
  8. Now, check with the new password, and you should log in without any issue.

    # mysql -u root -p

Was this answer helpful?

« Back
Sign up for a newsletter