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:<steve@example.com> 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 = but it says warning: connect to mysql server Can't connect to MySQL server on '' (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.


When I do netstat -na I see that mysql is not bind neither to localhost nor to Could it be the problem also?

bakhtiyor@ns1:~$ netstat -na | grep 3306
tcp        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.

| improve this answer | |
  • 1
    How to remove restriction? – Green Jul 19 '13 at 3:32
  • I want to connect via TCP, not through a socket. How can I do that? Thanks. – krisanalfa Dec 1 '15 at 9:23
  • Hi @Green, any solution u got on how to remove the restriction or rather how to find if there is restriction on port 3306? – Sushivam Nov 11 '16 at 5:40

I had a similar problem. Changing "hosts = localhost" to "hosts =" and setting bind-address to the same address fixed it for me (bind-address was set at for some reason)

| improve this answer | |
  • I was able to leave bind-address as (which was necessary for the clustering I was doing with galera), and just changed "host=" to switch it to using TCP. I decided on this instead of bind-mounting the socket into the Postfix chroot as others have done. – Sean Reifschneider Jun 5 '15 at 17:38

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 and restart MySQL

# /etc/mysql/my.cnf
bind-address =
| improve this answer | |
  • I did all you said and no results – Bakhtiyor Nov 14 '11 at 19:28
  • i mean i can connect to mysql using mysql -u username -p – Bakhtiyor Nov 15 '11 at 9:07
  • Should be "my.cnf" – jnunn Feb 8 '13 at 16:27

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.

| improve this answer | |

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.

| improve this answer | |
  • I don't think this answer is helpful. Problem was the blocked 3306 port, not broken MySQL packages. – Nephente Oct 4 '15 at 16:29
  • THIS COMMAND WILL REMOVE ANY PACKAGES DEPENDS TO libmysqlclientXX – krisanalfa Dec 1 '15 at 9:26
  • how to find the blocked port 3306? – Sushivam Nov 11 '16 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.