Vivek S
Vivek S

Reputation: 5550

(2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)")

I am running a django based web application with apache. I am able to connecto to mysql from python and linux shell but, when i run the server i am getting the following error. Where am i doing wrong?

OperationalError at /

(2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)")

Request Method:     GET
Request URL:    http://dev.ls.co.uk/
Django Version:     1.3
Exception Type:     OperationalError
Exception Value:    

(2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'   (2)")

Exception Location:     build/bdist.linux-x86_64/egg/MySQLdb/connections.py in __init__, line 187
Python Executable:  /usr/bin/python
Python Version:     2.4.3

Upvotes: 0

Views: 4342

Answers (2)

Navid
Navid

Reputation: 642

The socket file is not exists. You need to restart the mysqld.service Try this:

su

systemctl restart mysqld.service

Have you started mysql in different mode? if so, you need to kill the process of mysql and use above command. grep for mysql process in the process list to see the process id and kill the process

kill process_id

and issue previous command to restart service

Upvotes: 1

jpic
jpic

Reputation: 33420

According to this thread on mysql.com:

There are two things that could go wrong here:

  1. You don't have permissions to access the directory /var/lib/mysql/whatever.sock because mysql is the owner of the folder or
  2. /path/whatever.sock doesn't exist.

First, you should know what user apache runs as: try top command to find out the user. Then, use id thatusername command to figure what group it is in.

Then, you can read an article about debugging this kind of problem.

Upvotes: 1

Related Questions