0

I'm getting the following message:

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

I've looked into this question: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)', but my hosting (fat cow) doesn't allow SSH.

I looked in my php.ini file, but I didn't see anything that would be of use. I have sent them a ticket, but if I can figure out how to fix this that would be nice.

At first I was able to get it to connect, but I messed up some of the logins in php so how do I fix this?

I am using PHP 5.2 with mySQL_* (I know I need to change to PDO, but I need to do some reading about it first).

$local = "fatcowmysql.com";
$user = "user";
$pass = "pass";
$dbName = "dbName";

$connectMySQL=mysql_connect($local,$user,$pass);

$dbSelect=mysql_select_db($dbName); 
Community
  • 1
  • 1
Alex
  • 141
  • 8

1 Answers1

0

Your error message and code are not consistent with each other.

The given error message only appears if you're connecting via the specified UNIX socket, which only happens if the "hostname" is given as localhost.

If the socket doesn't exist there are two possibilities:

  1. MySQL isn't running, or
  2. Something else (accidentally?) deleted the socket file

If you want to try to connect over TCP/IP instead (and if MySQL is running on the same server as your PHP code) specify 127.0.0.1 instead of localhost.

Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • Is it possible that the web host has `fatcowmysql.com` linked to `localhost` somehow; a `hosts` file perhaps? – gen_Eric Feb 21 '13 at 19:09
  • 1
    @RocketHazmat AFAIK, no - the MySQL client library looks for the exact string "localhost" _in the connection string_ as a "pseudo-hostname" for "use the UNIX socket" _before_ trying a hosts lookup on the given name. – Alnitak Feb 21 '13 at 19:12
  • ok so I re uploaded some of my code just to be sure that I different version wasn't there. I had to try twice, but then again before I did upload Dreamweaver crashed, so something may have been lost and I didn't notice, or something of the like. – Alex Feb 21 '13 at 20:29