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

Fotis picture Fotis · May 23, 2012 · Viewed 23.2k times · Source

I am a newbie programmer, so I will need your help! Locally the webapp works ok with the db on it! When I uploaded the application on the cloudcontrol, it comes up with the following error:

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)!

I suppose I have not uploaded the db. This is the very first time I upload a webapp on a server so I do not know the exact steps that I have to follow in order to upload the db on a server. Cloudcontrol has documentation about mysql! I did follow the steps but the webapp comes with the same error!

Could you please tell me what steps I have to follow in order to make it working? I am sure that this error is due to lack of knowledge!

Answer

Mihai Stancu picture Mihai Stancu · Jun 10, 2012

Most likely the SQL server resides on a separate machine which you need to address via a host name or IP.

This means that in your code you should replace localhost with the hostname of the machine where the SQL server resides (ex.: mysql.s032.example.com).

Finding the address of the SQL machine should be easy enough if it's documented by the hosting company within their control panel. Or by asking the hosting providers' tech support to tell you the address.