Home >Database >Mysql Tutorial >How Can I Recover My MySQL Root Access After Accidental Deletion on OS X Using MAMP?
Regaining Access to MySQL after Deleting 'root' User
Accidentally deleting the 'root' user in MySQL can leave you stranded without any means to access or manage your database. Fortunately, there's a method to restore the 'root' user and its privileges on OS X using MAMP.
Step-by-Step Instructions:
Modify my.cnf: Locate the my.cnf file for MySQL, which is typically found in /private/etc/my.cnf. Under the [mysqld] section, add the following line:
skip-grant-tables
Access MySQL without Password: Open a terminal window and type:
mysql
This should prompt you for a password, but simply hit Enter to proceed.
Delete and Insert 'root' User: Execute the following MySQL commands:
DELETE FROM mysql.user WHERE user = 'root' AND host = 'localhost'; INSERT INTO mysql.user SET user = 'root', host = 'localhost', password = Password('whatevernewpassword'), ... (grant all necessary privileges) ...;
Replace 'whatevernewpassword' with your desired password.
With these steps, you should have successfully restored the 'root' user and set a new password. You can now access and manage MySQL as needed.
The above is the detailed content of How Can I Recover My MySQL Root Access After Accidental Deletion on OS X Using MAMP?. For more information, please follow other related articles on the PHP Chinese website!