PHP can't talk to MySQL after OS X 10.4.5 upgrade

I just tried to access one of my local dev sites (that is, running on my powerbook), and received the dreaded "mysql can't connect to socket" error:

Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'

I was sure MySQL was running (I could access it via the command line mysql tool, and MySQL Administrator). And it used to work... But sure enough, there is no directory /var/mysql, and no mysql.sock file in it. :-/

After a bit of digging around, I noticed that the php.ini file (/etc/php.ini.default) had been updated on Feb 8th, about the time OS X 10.4.5 was released. Hmm.

I don't remember customising this file, but it certainly didn't contain any customisation now. The "mysql.default_socket" setting was blank, meaning it would use the compiled-in default. I'm not sure whether PHP was upgraded with 10.4.5 and this changed the default, or if I had customised it previously and I've just forgotten. But either way, it was now looking for the MySQL socket in /var/mysql, and my version of MySQL (4.0.24) wasn't putting it there.

So I created this dir and set its owner to mysql:

sudo mkdir /var/mysql
sudo chown mysql /var/mysql 

and followed the instructions in this Apple support article by adding the following setting to /etc/my.cnf:

socket = /var/mysql/mysql.sock

socket = /var/mysql/mysql.sock

(The last two lines are not mentioned in the Apple article, but are required for the command line mysql utilities to work.)

A quick restart of the mysql server later, and all is good again.


comments powered by Disqus