Friday, August 31, 2012

Can't connect to local MySQL server through socket(mysql.sock'(2)) )


Fix: Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock'(2)
Just wanted to post this possible fix for people that are getting the following error when trying to start/restart MySQL, as this procedure worked perfectly for me.

Code:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
This is the procedure I followed:
 Code:
Techy: Login as root to WHM and look at the service status
Techy: See what all is red
Me: just eximstats and MySQL right now
Techy: Look in /var/lib/mysql
Me: there's more than one .err file
Techy: ls -l|grep err


Me: -rw-rw----    1 nobody   root         1227 May  5 09:21 C0001-planetXeonimaging.err
 -rw-rw----    1 nobody   root         1227 Jun 20 13:53 C0001-planetXeonRH9CP.err
 -rw-rw----    1 nobody   root         3915 Jun 26 02:24 domain.err
 -rw-rw----    1 mysql    root        13080 Jun 26 07:56 hostname.domain.com.err
 -rw-rw----    1 nobody   root         4068 Apr 29 18:29 localhost.localdomain.err


Techy: Look in hostname.domain.err
Techy: Show me the last lines of that file


Me: 040626 08:05:27  mysqld started
 040626  8:05:27  Can't start server : Bind on unix socket: Permission denied
 040626  8:05:27  Do you already have another mysqld server running on socket: /var/lib/mysql/mysql.sock ?
 040626  8:05:27  Aborting
 
 040626  8:05:27  /usr/sbin/mysqld: Shutdown Complete
 
 040626 08:05:27  mysqld ended


Techy: ps aux|grep mysql


Me: root     14658  0.0  0.0  3580  632 pts/2   
S    08:06   0:00 grep mysql


Techy: rm /var/lib/mysql/mysql.sock
Techy: service mysql start


Me: rm: cannot lstat `/var/lib/mysql/mysql.sock': No such file or directory


Techy: cd /var/lib
Techy: ls -l|grep mysql


Me: drwxr-x--x   88 nobody   root         4096 Jun 26 08:05 mysql/


Me: is that supposed to be that way?
Techy: Checking
Me: k
Techy: chown mysql:root mysql mysql
Techy: errr
Techy: chown mysql:root mysql
Techy: service mysql start
Me: shall i run that chown command in the top directory?
Me: or just the var/lib?
Techy: In /var/lib
Me: ok, ran service mysql start
Me: no confirmation or errors
Techy: ps aux|grep mysql
Me: WHM doesn't show it as running


Me: root     14696  0.0  0.1  4196 1180 pts/2   
S    08:11   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/hostname.domain.com.pid
mysql    14716  0.2  1.1 31208 11604 pts/2  
S    08:11   0:00 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/g
eekland.domain.com.pid --skip-locking
root     14744  0.0  0.0  3576  632 pts/2   
S    08:12   0:00 grep mysql


Techy: chskervd will pick it up in a few minutes
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
 Hello,

Did you check the partition size on file system?? I mean may be /var is 100% full on server. Thats the reason mysql could not be started on server.

MySQL sock file not found
====================

= killall -9 mysqld
= service mysql stop
=cp var/lib/mysql/mysql.sock var/lib/mysql/mysql.sock_backup
= rm -f /var/lib/mysql/mysql.sock
= service mysql start
= ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
= /scripts/restartsrv mysql

Hope this will help you to resolve this issue as it helps me always 


                                                                  OR 

Try and open up your /etc/my.cnf file and see if you can find this:

Code:
[mysql.server]
user=mysql
basedir=/var/lib
Comment out the basedir variable so that it looks like this:

Code:
[mysql.server]
user=mysql
#basedir=/var/lib
Then try and restart mysql and see if that fixes it.


No comments: