“mysql_connect(): [2002] No such file or directory” error on Apple OS

December 9, 2011

I ran into a problem setting up a php framework on a Mac Mini. Once I thought I had everything configured I found this error:

“Warning:mysql_connect(): [2002] No such file or directory”

I went and rechecked everything but without any results plus the error is not very descriptive of the problem.

After some search engine tech support, I realized this error is related to the mysql socket. It seems the OS can put the needed socket in different directories. In my case, it was in /tmp/mysql.sock while php was looking at /var/mysql/mysql.sock. I copied it to the path php was looking for and the error disappeared. This may happen the other way around where you’d need to copy the file to /tmp/mysql.sock but I am not sure what criteria gives what result.

Stay in Touch!

Subscribe to our newsletter.

Solutions Architecture

browse through our blog articles

Blog Archive