[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-04-27
8
Medium Priority
?
798 Views
Last Modified: 2012-05-06
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!
0
Comment
Question by:ducky801
  • 4
  • 4
8 Comments
 
LVL 4

Expert Comment

by:gunny051499
ID: 24243854
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
 
LVL 5

Author Comment

by:ducky801
ID: 24244175

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
 
LVL 4

Expert Comment

by:gunny051499
ID: 24253676
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:ducky801
ID: 24261862
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
 
LVL 4

Expert Comment

by:gunny051499
ID: 24262888
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
 
LVL 5

Author Comment

by:ducky801
ID: 24295592
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
 
LVL 4

Accepted Solution

by:
gunny051499 earned 2000 total points
ID: 24296738
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
 
LVL 5

Author Closing Comment

by:ducky801
ID: 31575028
This worked!!!  Thanks for the help!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question