Connectivity Issue: MySQL Error 2002: Permission Denied
When attempting to connect to a MySQL database, developers may encounter the error message "Error: Unable to connect to MySQL. Debugging errno: 2002 Debugging error: Permission denied." This error occurs when the user attempting to connect lacks the necessary permissions to access the database. While the error typically arises when connecting remotely, it can also occur on localhost.
Troubleshooting for Localhost Connections
If this issue manifests on localhost, the root cause may lie within SELinux security policies. Specifically, the policy "httpd_can_network_connect_db" must be enabled to grant the web server permission to establish a connection to the database. This setting can be verified using the command:
getsebool -a | grep httpd
If "httpd_can_network_connect_db" is set to "Off," it can be enabled using:
setsebool -P httpd_can_network_connect_db 1
This change will persist across reboots by virtue of the "-P" flag.
The above is the detailed content of Why Am I Getting MySQL Error 2002: Permission Denied on Localhost?. For more information, please follow other related articles on the PHP Chinese website!