nimana – weblog

Symfony Error: PDO Connection Error: SQLSTATE[HY000] [2002]

leave a comment »

PDO Connection Error: SQLSTATE[HY000] [2002] No such file or directory

Warning: PDO::__construct() [pdo.–construct]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in

This error occurs when the path to mysql.sock in the php.ini file (in the above case /var/mysql/mysql.sock) is incorrect (Thanks to this link). Please note that there may be multiple copies of php.ini on your system. The php.ini file that the webserver uses needs to be changed. To find which php.ini is your webserver using, use phpinfo(). In my case the location was /etc.

Once the correct php.ini is found, look for the property “pdo_mysql.default_socket” and point to the path where mysql.sock resides. To find where your mysql.sock resides, run this command (Thanks to this link):

mysqladmin variables

OR

mysqld --verbose --help | grep ^socket

On my system [Mac running MySql 5.1.50] the location was /tmp/mysql.sock.

Written by nimana

December 28, 2010 at 4:18 pm

Posted in Tech

Tagged with , , , ,