beyondmac.com|comments, answers, etc.

Home Contact About Subscribe(RSS)

The Book:

Buy Mac OS X Leopard: Beyond the Manual from Amazon, or check out the Apress website for more information.

Categories:

Bookmarks:

Powered by WordPress

PHP & MySQL on Leopard: mysql.sock Location | October 30, 2007

One thing I noticed setting up PHP and MySQL on Leopard, is that the default PHP build looks for the MySQL socket in /var/mysql/mysql.sock which doesn’t exist and isn’t the location that MySQL would use if it did (by default anyway). By default the MySQL socket is: /tmp/mysql.sock.

There are four ways to fix this:

  1. Create the /var/mysql directory (sudo mkdir /var/mysql) and then create a symbolic link from /tmp/mysql.sock to /var/mysql/mysql.sock (with: sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock).
  2. Edit the /etc/php.ini file (it may not exist in which case just sudo cp /etc/php.ini.default /etc/php.ini) so that the mysql.default_socket = /tmp/mysql.sock (by default line 760) and mysqli.default_socket = /tmp/mysql.sock (by default line 795).
  3. Edit /etc/my.cnf adding the following lines:
    [mysqld]
    socket=/var/mysql/mysql.sock
    [client]
    socket=/var/mysql/mysql.sock

    This will tell MySQL to create its socket where Leopard’s default PHP is looking for it. Next, you also need to create the /var/mysql directory and sudo chown mysql /var/mysql it or MySQL won’t start since it wont be able to create the socket.
  4. Recompile php for your version of MySQL (a PIA, but not a terrible idea at all).

Of these #1 is easiest, but a bit of a hack. #2 is the easiest real way. #3 isn’t to bad, but could cause issues with other MySQL clients that look for the socket in /tmp/mysql.sock. #4 is ultimately the best fix, but is clearly neither very fast nor particularly easy

5 Comments »

  1. Migrating MySQL 5.0.45 to Mac OS X 10.5 Leopard
    http://blog.tomatocheese.com/archives/2007/11/1/migrating_mysql_to_mac_os_x_leopard/

    Comment by Joannou Ng — November 1, 2007 @ 11:42 pm

  2. […] beyondmac(dot)com […]

    Pingback by insites » Blog Archive » MySQL in Leopard — November 8, 2007 @ 10:29 am

  3. Thank you for this, it was very easy to find on google and helped out quickly.

    Comment by Nate — November 29, 2007 @ 3:38 pm

  4. […] a good explanation of your choices in how to fix it. I like solution #1 unless you have the time and energy to tackle […]

    Pingback by Null is Love » Blog Archive » Taming Leopard for PHP — December 19, 2007 @ 2:10 pm

  5. This solved a headache I had for 2 days. You give not one but four solutions. Thanks. Leopard should have Mysql pre-installed just like PHP.

    Comment by hanafi — June 26, 2008 @ 9:42 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment