MySQL Error 1045: Troubleshooting and Resolution
Experiencing the error #1045, "Access denied for user 'root'@'localhost' (using password: YES)" when attempting to access MySQL using PHPMyAdmin can be frustrating. Here's a comprehensive guide to troubleshooting and resolving this issue:
Problem: Unable to log into MySQL using the mysql console due to an unknown password. PHPMyAdmin also returns an error message.
Solution:
Retrieve MySQL Root Password:
Open a command prompt and run the following command:
mysql -u root -p
Reset Root Password:
Execute the following command to update the password:
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
Update config.inc.php File:
Find the following line and replace the old password with the new password:
$cfg['Servers'][$i]['password'] = 'MyNewPass';
Cycle MySQL Service:
Additional Considerations for MySQL 5.7 and Higher:
If you are running MySQL version 5.7 or higher, use authentication_string instead of Password in the UPDATE query:
UPDATE mysql.user SET authentication_string=PASSWORD('MyNewPass') WHERE User='root';
By following these steps, you should be able to update your MySQL root password successfully and regain access to both the mysql console and PHPMyAdmin.
The above is the detailed content of How to Fix MySQL Error 1045: Access Denied for User \'root\'@\'localhost\' (using password: YES)?. For more information, please follow other related articles on the PHP Chinese website!