Can't connect to local MySQL server through socket '/tmp/mysql.sock' PDO exception

Can't connect to local MySQL server through socket '/tmp/mysql.sock' PDO exception

Post by Michal Sta » Thu, 31 Aug 2006 02:40:53


Hi

Environment: some version of Slackware, Apache 2.2.x, PHP 5.1.5, MySQL
5.0.24.

The issue: I'm using Zend Framework Zend_Db component (which uses PDO).
We have 2 mysql socket related settings in php.ini:

mysql.default_socket = /var/run/mysql/mysql.sock
mysqli.default_socket = /var/run/mysql/mysql.sock

On MySQL command prompt, query "SHOW VARIABLES LIKE '%socket%';"
returns the variable "socket" with correct (desired) value
"/var/run/mysql/mysql.sock".

But still, the output of phpinfo() contains the following lines in
mysql and mysqli sections, respectively:

MYSQL_SOCKET /tmp/mysql.sock
MYSQLI_SOCKET /tmp/mysql.sock

What's worse though is that PDO seems to be using the wrong
"/tmp/mysql.sock" socket and every once in a while the sites
mysteriously stop working and throw the following exception:

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

I need a solution how to force PHP/MySQL/PDO (whatever causes this) to
use the specified socket (and stop throwing exceptions). I know that
there is a "unix_socket" option I can use in PDO connection string, but
since I don't directly use PDO but use Zend_Db instead, this is not
possible. I just need PDO to KNOW. (I don't know if the wrong
MYSQL_SOCKET and MYSQLI_SOCKET lines from phpinfo() affect this in any
way...?)

Thank you very much.

Michal
 
 
 

Can't connect to local MySQL server through socket '/tmp/mysql.sock' PDO exception

Post by Colin McKi » Fri, 01 Sep 2006 05:19:34


<snip>

Have you checked /etc/my.cnf? The environment vars?

HTH

C.

 
 
 

Can't connect to local MySQL server through socket '/tmp/mysql.sock' PDO exception

Post by Michal Sta » Wed, 06 Sep 2006 04:25:03


I have checked MySQL environment variables and they held the correct
value ("/var/run/mysql/mysql.sock").

:-/

Michal