Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)-Collection of common programming errors
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 do mail from:
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 says Can'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 returns
unix 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 says warning: 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
-
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.
-
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
-
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)
-
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.