Skip to content

PHPUnit – Zend Server CE – Snow Leopard Mac OS X 10.6


Running PHPUnit on a Mac running Zend Server produces the following error message:

ERROR 1049 (42000): Unknown database 'databases;'
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!


Before we proceed with the solution, let’s ensure that our user account is in the wheel. To check this, bring up your terminal and type the following command:

dscl . -read /Groups/wheel GroupMembership

The output should display something like this:

GroupMembership: root

If your username doesn’t appear next to root.. let’s add it.

dscl . -append /Groups/wheel GroupMembership YOUR_USER_ACCOUNT

Replace YOUR_USER_ACCOUNT with your username.

Zend Server places the mysql.sock file in a location that the rest of the system doesn’t know about. The rest of the system is looking for /tmp/mysql.sock however Zend places the mysql.sock file in /usr/local/zend/mysql/tmp/mysql.sock.

To solve this, we need to create a symlink for mysql.sock in the /tmp directory.

sudo ln -s /usr/local/zend/mysql/tmp/mysql.sock /tmp/mysql.sock

Another thing to keep in mind is that the my.cnf file is also located in a special Zend directory. The rest of the system is going to look for the my.cnf file in the /etc directory. Let’s go ahead and create that sym link also.

sudo ln -s /usr/local/zend/mysql/data/my.cnf /etc/my.cnf


If you are using pdo_mysql, you will still receive the /tmp/mysql.sock not found issues everytime you reboot your machine, it’s best to simply pass the socket information with each connection.

For Zend Users:

   $params = array(
      'host'           => 'localhost',
      'username'       => '***',
      'password'       => '***',
      'dbname'         => '***',
      'unix_socket'    => '/var/run/mysqld/mysqld.sock',
      'driver_options' => $pdoParams
   $db = Zend_Db::factory('Pdo_Mysql', $params);

Non Zend Users:

$dbc = new PDO(
          'mysql:host=localhost;dbname=test;unix_socket=/var/run/mysqld/mysqld.sock', 'user',  'passwd'

Update – April 20th 2011

I have received numerous emails about the sym linking option in this article. This is what I have done to circumvent that.

You will need to locate your my.cnf which is the mysql configuration file and add the following entries:

Filename: my.cnf
#... entries removed
socket = /usr/local/zend/mysql/tmp/mysql.sock
#... entries removed
socket = /usr/local/zend/mysql/tmp/mysql.sock

Posted in PHP, Snow Leopard, Zend Server.

4 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Yoeran said

    I have the weirdest thing. My symlink for the mysql.sock disappears when I restart my Macbook. Do you have any idea what would be the cause of that? Thanks in advance!

  2. Steve Rhoades said

    Check to make sure that you have a socket entry in your my.cnf, another option is to pass the unix_socket when you create your MySQL connection.

    For example:

    $conn = mysql_connect("host:/usr/local/zend/mysql/data/tmp/mysql.sock", 'user','pass');

    If you are using zend framework you can add a db param:

    db.params.unix_socket = /usr/local/zend/mysql/data/tmp/mysql.sock
  3. Danie said

    Is there any option for adding the symlink to bash_profile?, so that it will be automatically gets created when Macbook starts, avoiding manual execution of the command.

  4. Steve Rhoades said

    @Danie, please review the updated article.

Some HTML is OK


(required, but never shared)

or, reply to this post via trackback.