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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michal Stankoviansky

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

    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_s ocket = /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_socke t" 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

  • Colin McKinnon

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

    Michal Stankoviansky wrote:

    We have 2 mysql socket related settings in php.ini:
    >
    mysql.default_s ocket = /var/run/mysql/mysql.sock
    mysqli.default_ socket = /var/run/mysql/mysql.sock
    >
    <snip>
    >
    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
    >
    Have you checked /etc/my.cnf? The environment vars?

    HTH

    C.

    Comment

    • Michal Stankoviansky

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

      Colin McKinnon wrote:
      Have you checked /etc/my.cnf? The environment vars?

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

      :-/

      Michal

      Comment

      Working...