Sunday, October 24, 2010

PHP code fails to access MySQL at first time through mysql.sock

At the very first time I attempted to access my MySQL database, on my Mac, through my very first PHP application, I ran into the following error message:

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

Fortunately, I managed to find a valuable piece of information at Apple's website, which guided me to do the following:

cd /var
sudo mkdir mysql <== this assumes the directory is missing cd mysql sudo ln -s /private/tmp/mysql.sock mysql.sock

It seems that, by default, there is a lock in

/private/tmp/mysql.lock

and according to the answer given at the website, the workaround above creates a symbolic link so that the lock appears in the right place.

I confess, it is not crystal clear to me, but it was just following the workaround step-by-step to get my environment up and running. It may happen to suit your needs someday.

Enjoy it!


2 comments:

  1. Thanks Marcos!

    You may want to fix the command lines:
    3 lines are merged into a single long line, that won't work. I guess that's a newline problem.

    Cheers!

    ReplyDelete
  2. Thank you for your comment, Nicolas! That was fixed in the past through what I mentioned above, more than 2 years ago :)

    ReplyDelete