2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

Asking on behalf of a friend:

I recently transferred my domain from one hosting co to Godaddy.com. All files have been transferred to my new hosting site. However, when going to the web page - www.treasuresforzoe.com - I'm getting the error - 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2).

I've read many forums and it appears to have something to do with permissions. I'm a beginner with MySQL and PHP at best so I'm unable to resolve. Can anyone please give me some basic, step-by-step instructions on how to resolve this, if it is something to do with cubecart? Much appreciation in advance!
LVL 5
ducky801Asked:
Who is Participating?
 
gunny051499Commented:
Hi ducky801,

all right then. I do think the database instance should be ok if it is a shared server, otherwise someone else would have noticed in the meantime ;-)

Please have a try with the code below (correct the password) and tell me what happens.

Cheers

Gunny
<?php
 
  $glob['dbdatabase'] = 'jmhuntle_ccrt1';
  $glob['dbhost'    ] = 'localhost:3307';
  $glob['dbusername'] = 'jmhuntle_ccrt1';
  $glob['dbpassword'] = 'omitted';
 
  $link = mysql_connect($glob['dbhost'], $glob['dbusername'], $glob['dbpassword']);
  if (!$link) {
    die('Could not connect: ' . mysql_error());
  }
  echo 'Connected successfully';
  mysql_close($link);
 
?>

Open in new window

0
 
gunny051499Commented:
Hi ducky801,

no idea about what cubecart or Godaddy.com is, but....

1) can you "see" /var/lib/mysql/mysql.sock ?
2) what are the rights there?
3) have you tried accessing mysql through TCP sockets instead of local unix sockets?

About the last question: you will need to find the place you are calling "mysql_connect". It should be enough to put the IP-address of your mysql server into the configuration file, where you configured your username + password. When using an IP address the mysql-client build into PHP won't try to use the unix socket.

Cheers

Gunny
0
 
ducky801Author Commented:

Thank you for the quick response! Cubecart is the shopping cart capability that I'm using on my website; it runs with PHP and MySQL. Godaddy is my hosting service.

I cannot see the /var/lib/mysql/mysql.sock anywhere so I can't answer your next two questions. Since I'm using godaddy as my hosting service, I'm doing everything thru their online interface so I'm unsure of how to find the IP address of the MySQL server.
There is a PHPMyAdmin tool that I can use to manage the content, as well as MySQL online interface.

Again, this is all very new to me so it's challenging to speak technically about it. I appreciate your help and patience.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
gunny051499Commented:
Hi ducky801,

very well. If you can't see /var/lib/mysql/mysql.sock (I assume you have shell access) this means there definitely is no such thing as a local unix socket and you need to connect through an IP address.

Maybe you are able to find the file "includes/global.inc.php" in your cubecart folder. That's where the settings are if http://www.siteground.com/tutorials/cubecart/cubecart_manual_installation.htm is correct.

Cheers

Gunny
0
 
ducky801Author Commented:
Gunny,

Yes, I have found and can access the code of the 'includes/global.inc.php' file on my hosting file manager. Here is the code for it. What in here should I change?

Thanks!

<?php
    
    $glob['dbdatabase'] = 'jmhuntle_ccrt1'          ;
    $glob['dbhost'    ] = 'localhost'        ;
    $glob['dbusername'] = 'jmhuntle_ccrt1'        ;
    $glob['dbpassword'] = 'omitted'        ;
    $glob['dbprefix'  ] = ''                   ;
    $glob['installed' ] = '1'                  ;
    $glob['rootDir'   ] = 'html/store'       ;
    $glob['rootRel'   ] = '/store/' ;
    $glob['storeURL'  ] = 'http://www.treasuresforzoe.com/store' ; 
?> 

Open in new window

0
 
gunny051499Commented:
Hi ducky801,

that's the one. The dbhost setting is what i was looking for.
But that setting is already set to localhost.

Is this system running a dedicated linux instance for you? Can you start/stop services on it? (inside your shell change to root user and execute "/etc/init.d/mysql start".

If you are not the admin of this system this won't work though. Please check what processes are running in case this should be a shared server (if cpanel is used that is quite probable). Issue "ps xa" to see all running processes and let me know.

Cheers

Günther
0
 
ducky801Author Commented:
Thanks Gunny,
 
This is a shared linux server and I have no administrative access to diagnostic tools, nor can I restart services, etc. From the code I sent, should I change something in it? I welcome your suggestions.
0
 
ducky801Author Commented:
This worked!!!  Thanks for the help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.