Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

After running Mac OS X updates this morning when I run PHP projects on my local machine, when they were fine last night are now giving me errors:

mysql_connect() [function.mysql-connect]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) [CORE/cake/libs/model/datasources/dbo/dbo_mysql.php, line 540]

Has anyone had a similar problem?


share|improve this question

From apple support forum :

I had the same problem and fixed it by editing my php.ini file:

  1. In Terminal type sudo nano /etc/php.ini (Terminal will ask you for your password)

  2. Change: mysql.default_socket = to: mysql.default_socket = /tmp/mysql.sock

  3. Press Ctrl-O, then Enter to save

  4. Still in Terminal, type sudo apachectl graceful

  5. That's it!

share|improve this answer
thanks for the link. It hasn't fixed it though, is it anything to do with me having a php.default.ini instead? – iamjonesy Sep 6 '10 at 17:39
I don't think PHP will read php.default.ini. This FAQ explains where to find php.ini - you might just rename php.default.ini to php.ini. – pjmorse Oct 19 '10 at 17:18
Also consider changing mysqli.default_socket = /tmp/mysql.sock for MySQLi and pdo_mysql.default_socket=/tmp/mysql.sock for PDO – Burak Erdem May 19 '11 at 17:11

It appears that MySQL is no longer running. How did you install MySQL? Does it report any error when you try to start/restart it?

share|improve this answer
it's running but when I try to restart it i get an error: Stopping server... ERROR! MySQL manager or server PID file could not be found! Failed to stop server, trying shutdown... Stopped server. – iamjonesy Sep 5 '10 at 11:57
I'm using MySQL Administrator for MacOSX btw – iamjonesy Sep 5 '10 at 14:39
Has your /etc/my.cnf file changed? Maybe you're connecting via TCP or something now? When in the mysql client, type \s to see where the socket is now (or if you're using TCP, etc) – barrycarter Oct 20 '10 at 19:00

you can start the mysqld deamon pointing to any socket file that you want. You just have to say to the client as well which file you want to use.

In your case i would:

  • check if the /var/mysql directory exists
  • check if your user has permission to write file on this directory

you can try to start your deamon using a socket file like:

mysqld_safe --socket=/tmp/mysql.sock

and then with your mysqlclient you can do something like

mysql -u user -p --socket=/tmp/mysql.sock

it will work

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.