Access Denied Error in MySQL: (HY000/1045)
Problem:
You encounter the following error when trying to connect to a MySQL database using mysqli_connect():
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES)
Copy after login
Explanation:
The error indicates that the user specified in the connection parameters ('username' in this case) does not have the necessary permissions to connect to the database server.
Solution:
To resolve this error, verify the following:
-
Confirm User Permissions: Ensure that the user with the username 'username' has the GRANT permission to connect to the database server from the host specified in the connection ('localhost' in this case). You can check this in the user's permissions table or by running the following SQL query:
SELECT * FROM mysql.user WHERE User = 'username' AND Host = 'localhost';
Copy after login
-
Check User Password: Verify that the password provided in the connection parameters ('' in this case) is correct. The error message indicates that the password is being provided, but it may be incorrect.
-
Reload Grants: If the user permissions have been modified, but the changes are not being reflected, reload the grant tables using the following command:
FLUSH PRIVILEGES;
Copy after login
-
Connect to the Correct Server: Ensure that you are connecting to the correct MySQL database server. Verify that the server address or hostname specified in the connection parameters is accurate.
-
Update Connection Parameters: If none of the above steps resolve the issue, refer to the official MySQL documentation for more advanced troubleshooting options, including resetting user passwords or creating new users: https://dev.mysql.com/doc/refman/8.0/en/managing-users.html
The above is the detailed content of MySQL Access Denied (HY000/1045): How Can I Fix This Error?. For more information, please follow other related articles on the PHP Chinese website!