Home >Database >Mysql Tutorial >Why Am I Getting a 'Connect Failed: Access Denied' Error When Connecting to MySQL with the Root User?
"Connect Failed: Access Denied" Error When Connecting to MySQL with Root User
When attempting to connect to a MySQL database using a PHP function, users may encounter the error: "Connect failed: Access denied for user 'root'@'localhost' (using password: YES)."
Reason:
This error typically occurs when the root user does not have the necessary permissions to access the database or when the password is incorrect.
Solution:
To resolve this issue, follow these steps:
Create a Non-Root User:
If the database has not yet been created, use the following command:
CREATE DATABASE shop;
Grant Privileges:
Log Out and In:
Import Data:
Update PHP Function:
By following these steps, you can establish a successful connection to the MySQL database and prevent the "Connect failed: Access denied" error.
The above is the detailed content of Why Am I Getting a 'Connect Failed: Access Denied' Error When Connecting to MySQL with the Root User?. For more information, please follow other related articles on the PHP Chinese website!