Fixing Mysql sock issue when using PHP on Snow Leopard

If you followed my tutorial pages about installing Apache + PHP + missing extensions and installing PEAR previously, maybe you are interested to look at this fix.

Installing MySQL is easy. Just go to MySQL Download page and grab the x86_64 DMG file.
Follow the installation instructions and do not forget to also install StartupItem.

As soon as you attempt to connect to MySQL, this error would popup for you:

Warning: mysql_connect() [function.mysql-connect]: [2002] No such file  or directory (trying to connect via unix:///var/mysql/mysql.sock) in ...

To fix that, the only necessary change is actually to create a symbolic link to the same location PHP is looking at (I would recommend to update php.ini config to point to the right file).

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

Restart your Apache and live happy!

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Fixing Mysql sock issue when using PHP on Snow Leopard

  1. Dmitry Belyakov says:

    Hi, Guilherme.

    First of all I want to thank you for your Bisna ZendFramework+Doctrine integration library. Some time ago I’ve struggled with the same issue with ZendServer storing mysql socket in it’s own directory and did just the same as you suggest #ln -s …

    But the problem was that I needed to do this each time I reboot (wich was getting a bit annoying), so a better approach may be to configure mysql to store the socket where it needs to be. This can be done in my.cnf with :

    [mysqld]
    socket= /tmp/mysql.sock #(or whatever)

    Hope that was to the point of your post.
    Dmitry.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">