Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Solution 1
It seems very stupid but I have solved the problem. I hadn't noticed that a system administrator somehow blocked 3306 port for all hosts at the firewall, and therefore I couldn't connect to mysql. After removing that restriction I was able to connect to mysql without any problems. Thanks for your suggestions and help.
Solution 2
I had a similar problem. Changing "hosts = localhost" to "hosts = 127.0.0.1" and setting bind-address to the same address fixed it for me (bind-address was set at 0.0.0.0 for some reason)
Solution 3
Have you tried to connect to the Mysql server?
mysql -u username -p
Also, you can try change the listen address in /etc/mysql/my.cnf to 127.0.0.1 and restart MySQL
# /etc/mysql/my.cnf
bind-address = 127.0.0.1
Solution 4
I was just getting this same error on one of the company computers.
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I was also getting this error a lot when I tried to run X-windows programs through ssh:
GConf Error: Failed to contact configuration server;
some possible causes are that you need to enable TCP/IP networking for ORBit,
or you have stale NFS locks due to a system crash
Turns out I had a root file system that was completely filled up, with no free disk space, so my system couldn't write a lot of necessary files. I was getting all sorts of errors, related to many different programs. (Couldn't log in through GDM, GDM wallpaper went black, gconf lock file errors, etc...)
All I did was enter this simple command to get rid of over 400 MB worth of files in the root partition that were no longer needed.
sudo apt-get autoremove
That gave my root file system the breathing space it needed. Now everything runs great. Guess a 10 GB root directory isn't enough to handle over two years worth of Ubuntu updates.
If anybody cares, the system has been running Ubuntu 10.04 since it came out. The system updates at least once a week. Today's date is 9-6-2012, so that's almost 2 1/2 years worth of updates.
Solution 5
What finally helped me was purging (not removing!) all the apt-get packages related to mysql except for libmysqlclient16
which was in de-install status (not sure what that is).
So, just do:
dpkg --get-selections | grep mysql
and then:
sudo apt-get purge <package_name>
Start from common then go to client and then the server.
Related videos on Youtube
Bakhtiyor
Updated on September 18, 2022Comments
-
Bakhtiyor almost 2 years
I have mailserver configure using dovecot+postfix+mysql and it was runnig fine in the server(Ubuntu Server). But during last week it stopped working correctly. It doesn't send email. When I try to
telnet localhost smtp
I'm connecting successfully but when I domail from:<[email protected]>
and hit Enter it hangs on, nothing happen.Having reviewed
/var/log/mail.log
file I've found out that probably(99%) the problem is on postfix when it is trying to connect to MySQL server. If you see the log file given below you can see that it saysCan't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
.Nov 14 21:54:36 ns1 dovecot: dovecot: Killed with signal 15 (by pid=7731 uid=0 code=kill) Nov 14 21:54:36 ns1 dovecot: Dovecot v1.2.9 starting up (core dumps disabled) Nov 14 21:54:36 ns1 dovecot: auth-worker(default): mysql: Connected to localhost (mailserver) Nov 14 21:54:44 ns1 postfix/postfix-script[7753]: refreshing the Postfix mail system Nov 14 21:54:44 ns1 postfix/master[1670]: reload -- version 2.7.0, configuration /etc/postfix Nov 14 21:54:52 ns1 postfix/trivial-rewrite[7759]: warning: connect to mysql server localhost: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) Nov 14 21:54:52 ns1 postfix/trivial-rewrite[7759]: fatal: mysql:/etc/postfix/mysql-virtual-alias-maps.cf(0,lock|fold_fix): table lookup problem Nov 14 21:54:53 ns1 postfix/master[1670]: warning: process /usr/lib/postfix/trivial-rewrite pid 7759 exit status 1 Nov 14 21:54:53 ns1 postfix/cleanup[7397]: warning: problem talking to service rewrite: Connection reset by peer Nov 14 21:54:53 ns1 postfix/master[1670]: warning: /usr/lib/postfix/trivial-rewrite: bad command startup -- throttling Nov 14 21:54:53 ns1 postfix/smtpd[7071]: warning: problem talking to service rewrite: Success
I tried
netstat -ln | grep mysql
and it returnsunix 2 [ ACC ] STREAM LISTENING 5817 /var/run/mysqld/mysqld.sock
.The content of
/etc/postfix/mysql-virtual-alias-maps.cf
file is here:user = stevejobs password = apple hosts = localhost dbname = mailserver query = SELECT destination FROM virtual_aliases WHERE source='%s'
Here I tried to change
hosts = 127.0.0.1
but it sayswarning: connect to mysql server 127.0.0.1: Can't connect to MySQL server on '127.0.0.1' (110)
So, I am lost and don't know where else to change in order to solve the problem. Any help would be appreciated highly.
Thank you.
EDIT 1
When I do netstat -na I see that mysql is not bind neither to localhost nor to 127.0.0.1. Could it be the problem also?
bakhtiyor@ns1:~$ netstat -na | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
-
Bakhtiyor over 12 yearsI did all you said and no results
-
Bakhtiyor over 12 yearsi mean i can connect to mysql using mysql -u username -p
-
jnunn over 11 yearsShould be "my.cnf"
-
yuval about 11 years+1 for pointing out space issue -- this solved my problem.
-
Garri Sumalapao Farol almost 11 yearsHow to remove restriction?
-
Sean Reifschneider about 9 yearsI was able to leave bind-address as 0.0.0.0 (which was necessary for the clustering I was doing with galera), and just changed "host=127.0.0.1:3306" to switch it to using TCP. I decided on this instead of bind-mounting the socket into the Postfix chroot as others have done.
-
Nephente over 8 yearsI don't think this answer is helpful. Problem was the blocked 3306 port, not broken MySQL packages.
-
krisanalfa over 8 yearsI want to connect via TCP, not through a socket. How can I do that? Thanks.
-
krisanalfa over 8 yearsTHIS COMMAND WILL REMOVE ANY PACKAGES DEPENDS TO
libmysqlclientXX
-
Sushivam over 7 yearsHi @Green, any solution u got on how to remove the restriction or rather how to find if there is restriction on port 3306?
-
Sushivam over 7 yearshow to find the blocked port 3306?