Main | October 2007 »

September 27, 2007

Enabling php connection to mysql on OS X

When trying to connect to mysql thru a simple php script on OS X, I got the error:

Can't connect to local MySQL server through socket php

I took the following steps to fix the bug:

1) cd /private/etc/ 2) sudo cp php.ini.default php.ini 3) Added to php.ini Added to php.ini: ; Default socket name for local MySQL connects. If empty, uses the built-in ; MySQL defaults. mysql.default_socket = /usr/local/mysql/run/mysql_socket

Note: I found out the name of mysql.default_socket by trying to
close the mysql server not usinf sudo

/usr/local/mysql/mysql-5.0.41/scripts/mysqld_safe --off
rm: /usr/local/mysql/run/mysql_socket: Permission denied

Note your location for mysqld_safe may differ. I put in the directory
level mysql-5.0.41

4) Restart apache:
sudo apachectl restart