• Register
1 vote
52 views

Problem :

I am very new to MySQL Server. I am newly assigned to this MySQL Server project. If I try to connect with the local MySQL server during my assigned test suite it shows me the below error:

 "Can't connect to local MySQL server through socket '/tmp/mysql.sock'”.

But still I can connect to the MySQL by running a command line MySQL program. The following command ps aux | grep mysql informs that my server is running also the below command stat /tmp/mysql.sock validate that my socket exists. Additionally if I try to open my debugger in except clause related to that exception I can connect with my exact same parameters.

I am very confused about above error. Can some expert help me in fixing it?

8 5 2
3,230 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution :

I know such errors are very annoying. I had faced this error earlier and was able to fix it.

The below command helped me.

sudo /usr/local/mysql/support-files/mysql.server start

If above command does not work for you then you need to make sure that the mysqld is running and then you can try connecting it again.

If still not working then you can try below process.

At your terminal you need to run below command

mysql_config –socket
Above command will provide you with your path to the sock file. You need to take that path and then you can use it in your DATABASES HOST paramater.

You need to do below in your DATABASES HOST parameter:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'test',
        'USER': 'test',
        'PASSWORD': 'test',
        'HOST': '/Applications/MAMP/tmp/mysql/mysql.sock',
        'PORT': '',
    },
}

It will surely fix the problem.

8 4 1
5,680 points

Related questions

0 votes
1 answer 22 views
22 views
Problem: How to fix this error > Can't connect to local mysql server through socket '/tmp/mysql.sock' (2) mac
asked Apr 30 ummeshani 10.8k points
0 votes
1 answer 4 views
4 views
Problem: What does this error mean > Error 2002 (hy000): can't connect to local mysql server through socket '/tmp/mysql.sock'
asked Apr 24 ummeshani 10.8k points
0 votes
1 answer 10 views
10 views
Problem: How to fix this issue? error: can't connect to local mysql server through socket '/tmp/mysql.sock' (2)
asked Apr 3 ashik 14.6k points
0 votes
1 answer 6 views
6 views
Problem: What are my options for dealing with this issue? mysql2::error: can't connect to local mysql server through socket '/tmp/mysql.sock' (2)
asked Apr 1 rakib1 51.5k points
0 votes
1 answer 24 views
24 views
Problem: How to fix this Error 2002 (hy000): can't connect to local mysql server through socket '/tmp/mysql.sock' (38).
asked Apr 1 rakib1 51.5k points
0 votes
1 answer 3 views
3 views
Problem: I am getting the following error when I try to connect to mysql: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Is there a solution for this error? What might be the reason behind it?
asked Apr 30 ochena 23.3k points
0 votes
1 answer 12 views
12 views
Problem: HELP! I need help understanding this error > Cant connect to local mysql server through socket /var/run/mysqld/mysqld.sock
asked Apr 29 ummeshani 10.8k points
0 votes
1 answer 8 views
8 views
Problem: Is there a solution for this error? What might be the reason behind it?
asked Apr 28 salim1 60.6k points
0 votes
1 answer 4 views
4 views
Problem: I am getting the following error when I try to connect to mysql: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Is there a solution for this error? What might be the reason behind it?
asked Apr 26 ochena 23.3k points
0 votes
1 answer 5 views
5 views
Problem: My problem started off with me not being able to log in as root any more on my mysql install. I was attempting to run mysql without passwords turned on... but whenever I ran the command # mysqld_safe --skip-grant-tables & I would never get the prompt back. I ... mysql-client again. But I've noticed that it doesn't prompt me for a password. Isn't it supposed to ask for an admin password?
asked Apr 20 munim01 21k points