/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

About these ads

~ by panoskrt on March 2, 2009.

9 Responses to “/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. 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. Just wanted to verbalize my thanks for this entry. Your suggestions fixed my OS X / WordPress issue.

  5. 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!

  6. 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

  7. [...] Figuring out how to get the PHP pre-installed with OS X to communicate with MySQL. [...]

  8. 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!

  9. [...] Figuring out how to get the PHP pre-installed with OS X to communicate with MySQL. [...]

Leave a Reply

Fill in your details below or click an icon to log in:

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 )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: