Bootstrap FreeKB - mySQL / MariaDB - Resolve "ERROR 2002 [HY000] Permission denied"
mySQL / MariaDB - Resolve "ERROR 2002 [HY000] Permission denied"

Updated:   |  mySQL / MariaDB articles

Let's say the following is displayed when attempting to connect to mySQL or MariaDB.

SQLSTATE[HY000] [2002] Permission denied

 

On a Linux system, this may be due to SELinux being configured with the httpd_can_network_connect_db boolean set to off.

~]# getsebool httpd_can_network_connect_db
httpd_can_network_connect_db --> off

 

The setsebool command can be used to turn the boolean on. Make sure to include the -P (permanent) flag, so that the setting survives reboots.

~]# setsebool -P httpd_can_network_connect_db on

 

This error appears when attempting to make a connection to MySQL or MariaDB using PHP. Following are a list of things to check when this error appears.

  1. Ensure you are port forwarding on ports 80 and 443 in your router
  2. In your PHP connection string, try to connect using the IP address of the LAMP server. If the connection is successful when using the IP address but fails when using the domain name, this suggests there is no entry in the /etc/hosts file on the LAMP server mapping the domain name to the IP address. Map the IP address to the domain name in the /etc/hosts file on the LAMP server.
  3. Make sure you can ping example.com



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


March 16 2023 by Mango
THANK YOU! I literally spent *hours* trying to figure out why my web server would not connect to a remote database. "Permission denied" was NOT a helpful error message!

Add a Comment


Please enter b48a79 in the box below so that we can be sure you are a human.