To reset the MySQL root password, you can follow these steps:
-
Stop the MySQL Service:
First, you need to stop the MySQL service. You can do this using the following command:sudo systemctl stop mysql -
Start MySQL in Safe Mode:
Start MySQL in safe mode with the--skip-grant-tablesoption, which allows you to access the database without a password:sudo mysqld_safe --skip-grant-tables & -
Log in to MySQL:
Open a new terminal and log in to MySQL as the root user:mysql -u root -
Reset the Password:
Once you are in the MySQL shell, run the following commands to reset the root password. Replacenew_passwordwith your desired password:FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; -
Exit MySQL:
Exit the MySQL shell:EXIT; -
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 -
Start MySQL Normally:
Start the MySQL service normally:sudo systemctl start mysql -
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.
