Bug #61011 Use Apple's default socket /var/mysql/mysql.sock rather than /tmp/mysql.sock
Submitted: 30 Apr 2011 0:52 Modified: 9 Jan 2015 15:56
Reporter: Sierk Bornemann Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: Installing Severity:S4 (Feature request)
Version:5.0.x, 5.5.x, 5.6.x OS:MacOS (10.6+)
Assigned to: CPU Architecture:Any
Tags: socket

[30 Apr 2011 0:52] Sierk Bornemann
Description:
Use /var/mysql/mysql.sock rather than /tmp/mysql.sock as default socket.

Apple has chosen /var/mysql/ as place for the MySQL socket file at least on MacOSX Server. Consequently, Apple ships its PHP and /etc/php.ini file on MacOSX Server and on MacOSX Client with referencing /var/mysql/mysql.sock as default location of the socket file.

The MySQL installer package from mysql.com uses /tmp/mysql.sock per default.
This conflicts with Apples default location /var/mysql/mysql.sock.
Currently, one of both (php.ini or mysql.com's MySQL installation with my.cnf) has to be manually adjusted by the system's admin. That could be easily prevented/circumvented, if mysql.com's MySQL package for MacOSX would simply follow Apple's filesystem layout at this particulary topic instead of using the default file layout for Unix systems.

How to repeat:
Install MySQL from mysql.com

Suggested fix:
I would recommend to adjust mysql.com's default socket location on MacOSX to what Apple indicates: /var/mysql/mysql.sock

See also Apple's patch to achive that for their default shipped PHP:

http://opensource.apple.com/source/apache_mod_php/apache_mod_php-53.4/patches/mysql_sock.p...

and Apple's Makefile for MySQL:

http://opensource.apple.com/source/MySQL/MySQL-54/Makefile

Apple's config options:

--localstatedir=/var/mysql
--sysconfdir=/etc
--with-unix-socket-path=/var/mysql/mysql.sock

Additionally, it might be useful to place a Symlink in /tmp to please unix applications that expect for any reason the socket file at /tmp/mysql.sock :

ln -s /var/mysql/mysql.sock /tmp/mysql.sock
[30 Apr 2011 7:57] Valeriy Kravchuk
Thank you for the feature request.
[1 May 2011 13:16] Sierk Bornemann
Additionally, the MySQL Workbench application on MacOSX may also need an adjustment to look per default for /var/mysql/mysql.sock rather than /tmp/mysql.sock.
[18 Dec 2011 19:18] Sierk Bornemann
Since Apple has abandoned MySQL in favor to PostgreSQL from MacOSX Lion on, please read:

Apple Developer Library: Release Notes MacOSX Lion -> What's new in MacOSX? -> Database Server Replacement
http://developer.apple.com/library/mac/releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10...

-- quote --
Database Server Replacement

Beginning in Mac OS X v10.7, Mac OS X Server ships with PostgreSQL instead of MySQL as its database server. If you are using other software that requires MySQL, you must install it yourself.

You can find downloads and installation instructions for MySQL at the MySQL Community Edition site, http://www.mysql.com/downloads/mysql/.

In addition to the directions linked to above, you must manually reconfigure PHP if you use it to work with MySQL databases. Previous versions of PHP obtained their default values for mysql.default_port and mysql.default_socket from the mysql-config command-line tool. Because this tool is no longer available, you must explicitly define these values in /etc/php.ini.

The default port for MySQL is traditionally 3306, and the traditional socket on Mac OS X was /var/mysql/mysql.sock. For more information about the available directives, see http://us3.php.net/manual/en/mysql.configuration.php.
-- /quote --

Concerning this, it might be one decision to stick to /tmp/mysql.sock rather than change it to /var/mysql/mysql.sock. But otherwise, MacOSX generally seems storing .socket files and .pid files in /var/run/ or in an appropriate directory below /var/ (e.g /var/mysql/, /var/amavis/, /var/named/ or /var/pgsql_socket/) rather than storing them below /tmp/.