/var/mysql/mysql.sock on OS X

Looks like that by default the mysql.sock file on OS X is stored under /tmp/. That causes problems wheh applications try to connect to the MySQL instance via /var/mysql/mysql.sock.

Quick solution: create symlink of /tmp/mysql.sock to /var/mysql/mysql.socn

9 thoughts on “/var/mysql/mysql.sock on OS X

  1. /tmp/mysql.sock is the default location for sockets (in unix these are real sockets) for all unix OSes. Instead of it Linux machines prefer the /var/mysql/mysql.socn.
    I would suggest you to keep the default. If your app fails to connect with mysql db, you could update the configuration file of your application. For example in RubyOnRails my configuration file seems like that:
    production:
    adapter: mysql
    encoding: utf8
    database: myprod_db
    username: myuser
    password: mypasswd
    socket: /tmp/mysql.sock
    The soft link it’s ok, but i think there is no need of it.

  2. panoskrt

    Vageli, thanks for the comment. I had a better look at the issue🙂

    I never had to setup MySQL on non-Linux machine before so I’d except things to just work. Linux though uses /var/lib/mysql/ for the socket location, not /var/mysql. Also, the default my.cnf configuration file on OS X (which I just realised has template files under /support-files) points to /tmp/mysql.sock. But looks like that the PHP configuration looks under /var/mysql/mysql.sock. I checked /etc/php.ini, the corresponding entry for the mysql socket was null and I changed that to /tmp/mysql.sock and then got it workig.

    I wanted to install Drupal. I couldn’t see anywhere any options for defining the location of the socket and therefore I created the softlink (which I don’t think is of any harm). Changing the my.cnf to use /var/mysql/mysql.sock I’m afraid it may break other applications. Therefore it looks like that the best solution is to either change the configuration of the specification application, as you suggested, or alter the generic /etc/php.ini file.

  3. Better yet, edit /etc/my.cnf (which won’t exist at first) and add the following four lines:

    [client]
    socket = /var/mysql/mysql.sock
    [mysqld]
    socket = /var/mysql/mysql.sock

    Be sure to make /var/mysql/ owned by “_mysql” first, so mysql can write its socket there.

    This is a good place to put it, because the built-in PHP has been compiled to look for that path.

  4. Jeremy

    Thank you, thank you, thank you! I have been pissing around with this issue for the last 6+ hours. Editing /etc/php.ini.default didn’t work. Creating php.ini as a copy of php.ini.default and editing it didn’t work. Your symlink idea worked, hot damn!

  5. Jeremy

    I did have to make a new directory “mysql” in /var because it didn’t exist yet:

    sudo mkdir /var/mysql

    Then I could create the symbolic link inside that new mysql directory:

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

  6. Pingback: My new user experience with Wordpress 3 | Jason Hendriks

  7. Will

    Thanks everyone for posting about the /var/mysql/mysql.sock on OS X. I was able to use the info Jeremy posted. It worked great. Thanks again!

  8. Pingback: Word-Pressing is awesome ! | Albab Saifi

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s