HostOnNet Blog

Zend Framework error MySQL server through socket /tmp/mysql.sock

Looking for Linux Server Admin or WordPress Expert? We can help.

On a new apache/mysql installation, i got following error when connecting to mysql database in zend framework.

An error occurred
Application error
Exception information:

Message: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

This is because no socket /tmp/mysql.sock exists. Can be fixed by symlink to actual socket.

To find mysql socket, in mysql command prompt run

mysql> show variables like '%socket%';
| Variable_name | Value                       |
| socket        | /var/run/mysqld/mysqld.sock | 
1 row in set (0.00 sec)


Now we got actual socket location. Now create a symlink with command

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

This will make it work, but a reboot will lose the changes, so permanent solution is to edit /etc/mysql/my.cnf

vi /etc/mysql/my.cnf 


socket          = /var/run/mysqld/mysqld.sock

Replace with (all occurrence, 3 times)

socket          = /tmp/mysql.sock

Posted in Programming

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.