Can't connect to MySQL server on '127.0.0.1' + Postfix

9,624

Solution 1

In your postfix mysql connection section, I think you want:

hosts = unix:/var/run/mysqld/mysqld.sock

rather than 127.0.0.1 for postfix. Alternatively, add a grant to allow postfix to connect via 127.0.0.1 rather than localhost.

grant all on postfix.* to [email protected] identified by 'asdf';

Postfix is connecting via TCP, you probably have the grant defined for the socket connection. Fixing one or the other should fix it.

Solution 2

I suspect a firewall might be messing things up. Try telnetting to localhost on port 3306: telnet localhost 3306 or telnet 127.0.0.1 3306 and see if that connects.

If it does not, try disabling your firewall: sudo ufw disable, then try telnetting again. If it does connect, we've identified your firewall settings as being the culprit, you will need to allow TCP access on your lo interface to/from 127.0.0.1 on port 3306.

Share:
9,624

Related videos on Youtube

APR
Author by

APR

Technical Expert at Atos

Updated on September 17, 2022

Comments

  • APR
    APR almost 2 years

    I just installed Postfix and configured it to use MySQL. It wasn't sending any emails out after I did that so I checked /var/log/mail.log and it came back with this:

    postfix/trivial-rewrite[5283]: fatal: proxy:mysql:/etc/postfix/mysql-domains.cf(0,lock|fold_fix): table lookup problem
    postfix/cleanup[5258]: warning: AFCDC30437: virtual_alias_maps map lookup problem for [email protected]
    postfix/master[4761]: warning: process /usr/lib/postfix/trivial-rewrite pid 5282 exit status 1
    postfix/proxymap[4126]: warning: connect to mysql server 127.0.0.1: Can't connect to MySQL server on '127.0.0.1' (110)
    

    In mysql-domains.cf I'm using:

    Hosts    127.0.0.1
    

    I can connect to MySQL with this:

    mysql -u postfixuser -p
    

    But I can't connect this way:

    mysql -u postfixuser -h 127.0.0.1 -p maildbname
    

    Also when I run netstat -l it comes back with:

    tcp        0      0 localhost:mysql         *:*                     LISTEN
    

    I've tried changing my hosts to:

    Hosts    localhost
    

    But then I just get a socket error:

    postfix/cleanup[4870]: warning: connect to mysql server localhost: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
    

    I also have this set up in the MySQL config file:

    bind-address            = 127.0.0.1
    

    Any idea what could be wrong?

    • Craig
      Craig over 12 years
      Be aware that localhost != 127.0.0.1 in mysql. When you use "localhost" in mysql it attempts to use the socket instead of a tcp connection to 127.0.0.1
  • e.a.
    e.a. about 14 years
    Ok....neither one of those worked either, but I think I found out what my problem was. I apparently botched something up in the reverse DNS. So I fixed that and now it seems to work.