Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

I am using Pagodabox PHP cloud platform where we HAVE TO indicate which socket to use to connect to MySQL. Here is the config file where I indicate to use my socket.




'db'=>array(

	'username' => DB_USER,

	'password' => DB_PASS,

	'connectionString' => 'mysql:host=' . DB_HOST . ';socket=' . DB_SOCK . ';dbname=' . DB_NAME,

	'emulatePrepare' => true,

	'charset' => 'utf8',

	'tablePrefix' => 'tbl_',

	'enableProfiling' =>false,

    'enableParamLogging'=>false

),



The constants are correctly set, so the DB_SOCK = "/tmp/mysql/mydbname.sock". However, I keep receiving the following error:


Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

So, I suppose that Yii does not pass user defined socket value to the PDO driver, which in this case uses its default "/var/run/mysqld/mysqld.sock".

Can you confirm that this is a Yii bug and if there is a fix for it, otherwise, I am stuck. There is no way to connect to DB without indicating the socket.

what is the value of DB_HOST… .if yo uuse names like "localhost" try with the IP address like 127.0.0.1

If I change localhost to 127.0.0.1 I start getting another error:


CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2013] Lost connection to MySQL server at 'reading initial communication packet', system error: 110

And it never fades away, i.e. no way to establish successful connection.

It’s highly likely that this is something to do with user defined socket passing to a PDO. I feel like Yii forgot to pass it through. Changing to 127.0.0.1 - I don’t think it would solve, there is no big reason for it to influence the work.

Check this documentation it can help you - http://php.net/manua…connection.php

NOTE: there is no "socket" but "unix_socket"

And especially check this note

You were right! Here is the final working config:


'db'=>array(

	'username' => DB_USER,

	'password' => DB_PASS,

	'connectionString' => 'mysql:unix_socket=' . DB_SOCK . ';dbname=' . DB_NAME,

	'emulatePrepare' => true,

	'charset' => 'utf8',

	'tablePrefix' => 'tbl_',

	'enableProfiling' =>false,

	'enableParamLogging'=>false

),

  1. Removed "host" info.

  2. Used "unix_socket".

Thanks.