You may need to reset your MySQL root password if you lose or forget it. MySQL stores the existing password in the user table.
To update the same password, we need to bypass the MySQL authentication.
Please refer to the following steps to reset the MySQL root password using --skip-grant-tables.
1. Log in to your server using SSH.
2. Stop the MySQL service using this command –
# systemctl stop mysqld.service
3. Run the below-given 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 this command –
# FLUSH PRIVILEGES;
6. Run the query given below 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 this command –
# systemctl stop mysqld.service# systemctl start mysqld.service
8. Now, with the new password, you should be able to log in without any issues.
# mysql -u root -p
# FLUSH PRIVILEGES