How to Recover Root Privileges in MySQL Using --skip-grant-tables
In case you accidentally locked yourself out of your MySQL database by revoking root privileges, here's a step-by-step guide to regain access using the --skip-grant-tables option.
Prerequisites:
Steps:
Stop the MySQL Service:
Open the Administrator Tools and go to Services. Locate the MySQL service and stop it.
Edit the Configuration File:
Locate the MySQL configuration file (my.ini or my.cnf) on your system. The default locations are:
Add the --skip-grant-tables Option:
In the [mysqld] section of the configuration file, add the following line:
skip-grant-tables
Restart the MySQL Service:
Return to the Services window and start the MySQL service again.
Log In Without a Password:
Open a command prompt and log in to MySQL. You should now be able to access the database without entering a password.
Reset the Root Password (Optional):
If desired, you can reset the root user's password by running the following command:
ALTER USER 'root'@'localhost' IDENTIFIED BY '<new_password>';
Remove the --skip-grant-tables Option:
Once you have regained access, be sure to remove the --skip-grant-tables option from the configuration file and restart the MySQL service.
The above is the detailed content of How to Recover MySQL Root Access After Accidentally Revoking Privileges?. For more information, please follow other related articles on the PHP Chinese website!