Thursday, January 12, 2012

Not Connected: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'(2)

1. Mysql Configuration Issue
2. Server admin or Installation person can check this.


Possible Reasons

1. Disk can fulled
2. check if that file available /var/lib/mysql/mysql.sock

Development Side Solution:

Solution 1

try using the local ip address (127.0.0.1) instead of 'localhost' in mysql_connect().
This "forces" php to connect through TCP/IP instead of a unix socket.


Configuration Side Solutions:

Solution 2
   
If your file my.cnf (usually in the etc folder) is correctly configured with

socket=/var/lib/mysql/mysql.sock

you can check if mysql is running with the following command:

mysqladmin -u root -p status

try changing your permission to mysql folder. If you are working locally, you can try:

sudo chmod -R 777 /var/lib/mysql/


Solutions 3

--Check your mysqld service is running or not, if not run, start the service.

--still your problem isn't solved, look for /etc/my.cnf. and modify as following, where you see a line starts with socket. Take a backup of that file before doing this update.

socket=/var/lib/mysql/mysql.sock 

    change to

 socket=/opt/lampp/var/mysql/mysql.sock -u root


Solutions 4:

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

[mysql.server]
user=mysql
basedir=/var/lib

Comment out the basedir variable so that it looks like this:

[mysql.server]
user=mysql
#basedir=/var/lib

Then try and restart mysql and see if that fixes it. 

No comments:

Post a Comment