jwallace.us

tech, tunes, and other stuff

Setting Up PHP to Work With MySQL in OSX SL

In OSX Snow Leopard, you may be seeing errors like these:

Warning: PDO::__construct(): [2002] No such file or directory
(trying to connect via unix:///var/mysql/mysql.sock)
in /Users/john/src/php/dbtest.php on line 5
Failed: SQLSTATE[HY000] [2002] No such file or directory

So, to correct this, first create a my.cnf file in /etc containing the following:

/etc/my.cnf
1
2
3
4
[client]
socket=/var/mysql/mysql.sock
[mysqld]
socket=/var/mysql/mysql.sock

Then create this directory using sudo:

sudo mkdir /var/mysql

Then create a link:

sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

That should fix the problem.