Hi,
this issue came to me after i got “Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’” on a mysql connection on php on a fresh installed mac – php connect’s correctly to 127.0.0.1 , but does not connect to localhost .
On a mac the default mysql socket is ‘/private/tmp/mysql.sock‘ and not ‘/var/mysql/mysql.sock’, you can confirm it by using $ locate mysql.sock on a Terminal.
So basically you have to change the php default connection socket to mysql to ‘/private/tmp/mysql.sock‘ . To do this you have to edit your php.ini – probably located at ‘/private/etc/php.ini‘ – via:
- $ sudo nano /private/etc/php.ini
- ctrl+w (where is) “mysql.default_socket“
- alter to “mysql.default_socket = /private/tmp/mysql.sock”
- crtl+x followed by y and enter to save php.ini
- $ sudo httpd -k restart to restart Apache 2
Retry connecting to mysql localhost on php – should be working :)
Update:
if you use mysqli you also must set “mysqli.default_socket = /private/tmp/mysql.sock” on php.ini;

![[del.icio.us]](http://techtrouts.com/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://techtrouts.com/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://techtrouts.com/wp-content/plugins/bookmarkify/facebook.png)
![[Twitter]](http://techtrouts.com/wp-content/plugins/bookmarkify/twitter.png)
February 16th, 2010 at 11:05 pm
You can also create a symbolic link:
sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock
That solved the problem here.