A while ago I installed Zend Server Community Edition on OS X which was pretty straightforward. It was only recently that I found out that, as opposed to
mysql which worked fine,
mysqldump didn’t work correctly and terminated with the error:
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect
Inspecting the mysql configuration contained in
/usr/local/zend/mysql/data/my.cnf confirmed that the section [client] showed the socket as returned by executing
SHOW VARIABLES; from the mysql client:
Although it is possible to specify the socket by using mysqldump’s
--socket switch, that doesn’t really seem a ‘solution’.
Apparently mysqldump, as opposed to the mysql client does not use the server-specific settings contained in
/usr/local/zend/mysql/data/my.cnf. The comments in my.cnf state:
# You can copy this file to # /etc/my.cnf to set global options, # mysql-data-dir/my.cnf to set server-specific options (in this # installation this directory is /usr/local/zend/mysql/data) or # ~/.my.cnf to set user-specific options.
/etc/my.cnf mysqldump worked as expected.
/etc/my.cnf I have included only the setting needed to get mysqldump running:
# Specifying socket to use for mysql/mysqldump # For other settings refer to /usr/local/zend/mysql/data/my.cnf [client] socket = /usr/local/zend/mysql/tmp/mysql.sock
Hope this saves anyone running into the same issue some time.
Update (alternative solutions):
As Joel Clermont pointed out it is also possible to create a symlink on the socket location expected by mysqldump to the real socket location. This can be done by executing:
ln -s /usr/local/zend/mysql/tmp/mysql.sock /tmp/mysql.sock
Another possible approach is to create a symlink at
/usr/local/zend/mysql/data/my.cnf. This has the downside that it requires loosening the default permissions (
drwxr-x---) on the data folder by allowing ‘others’ to enter it. Commands to execute:
sudo chmod o+x /usr/local/zend/mysql/data
sudo ln -s /usr/local/zend/mysql/data/my.cnf my.cnf
Granting more permissions can be a security consideration but on most development setups this probably won’t be an issue.
Additional info about Zend Server CE on OS X: