Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is the gist of my problem: I have a web application that won't connect when the database has the host is set as localhost, however it will if I use the address The error that PHP gives me when connecting is: "SQLSTATE[HY000][2002] Permission denied". I know that the socket is there because when I stop the service I get "SQ:STATE[HY000][2002] No such file or directory."

After I type in "ls -als /tmp" in the terminal, I see that mysql.sock has the permissions of 777.

Any ideas why I cannot connect to the socket?

share|improve this question

Does your mysql.user table have an entry for your database user for localhost host? If not, that is the reason for Permission denied error from MySQL.

share|improve this answer
Yes, it does have an entry for the user for localhost. – Travis Pessetto Apr 17 '14 at 19:10
Have you checked PHP's configuration that it tries to use the socket in /tmp/mysql.sock? Can you connect to MariaDB using mysql -u user@localhost -p and entering the password? – Tero Kilkanen Apr 17 '14 at 19:13
I've manually edited the php.ini file to point to /tmp/mysql.sock. No, I cannot connect using mysql -u user@localhost -p. – Travis Pessetto Apr 17 '14 at 19:22
I am thinking it may have something to do with SELinux on CentOS – Travis Pessetto Apr 17 '14 at 23:19

SELinux was causing problems. Need to add a rule to allow it to write to the socket's directory. As for now, I simply disabled SELinux and it worked, so I know it is SELinux causing the problem.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.