postfix can't connect with mysql table when using unix socket. postmap succeeds though? [closed]
Asked Answered
O

1

5

Postfix is throwing up an error saying:

Jul 9 14:41:26 tmail postfix/trivial-rewrite[4342]: warning: connect to mysql server unix:/var/run/mysqld/mysqld.sock: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) Jul 9 14:41:26 tmail postfix/trivial-rewrite[4342]: fatal: mysql:/etc/postfix/mysql-yaa-aliases.cf(0,lock|fold_fix): table lookup problem

In main.cf I have:

virtual_alias_maps = mysql:/etc/postfix/mysql-yaa-aliases.cf

In mysql-yaa-aliases.cf I have:

hosts = unix:/var/run/mysqld/mysqld.sock
# hosts = 127.0.0.1
user = yaa_admin
password = ********
dbname = yaa
query = SELECT dest FROM yaa_active_aliases WHERE address='%s'

If I use 127.0.0.1 it works (not ideal as I would prefer the speed of a socket.) Also if I test the socket with postmap it works:

# postmap -q "[email protected]" mysql:/etc/postfix/mysql-yaa-aliases.cf
[email protected], [email protected]

When I use strace on the trivial-rewrite daemon I get:

connect(11, {sa_family=AF_FILE, path="/var/run/mysqld/mysqld.sock"}, 110) = -1 ENOENT (No such file or directory)

Whereas strace using postmap I get:

connect(4, {sa_family=AF_FILE, path="/var/run/mysqld/mysqld.sock"}, 110) = 0

BTW - Currently running Postfix 2.7, but the fault still shows with 2.9

Ozonize answered 9/7, 2012 at 4:48 Comment(1)
BTW postmap tests succeed with both unix: and 127.0.0.1 linesMajormajordomo
O
13

FOUND IT :) - trivial-rewrite takes place in a chroot jail, therefore the socket file REALLY doesn't exist.

The solution (thanks to https://serverfault.com/questions/229389 for helping me with this) is to add this to the /etc/fstab:

/var/run/mysqld /var/spool/postfix/var/run/mysqld bind defaults,bind 0 0

Thus allowing Postfix to keep its chroot config, and giving it access to the mysql socket.

Ozonize answered 10/7, 2012 at 2:51 Comment(4)
How about using as host value 127.0.0.1? It helped me to solve this issue. It uses TCP connection which doesn't write socket (unlike localhost value on unix).Klotz
I think using a TCP connection is a better solution. Would be worthy of being a separate answer to this question. EDIT: I see, the question's closed. Oh well, I got my answer ;-)Eme
@Klotz I am trying to use 127.0.0.1 but still get the error Can't connect to MySQL server on <my_ip_address> . Any pointers?Liverish
@Klotz Very old comments, but worth answering. When both methods are possible, unix sockets are always preferable. There was a time when it would be considered wrong to use TCPIP over unix sockets for a local connection. Today CPUs are fast enough that more people use that shortcut. But engaging the TCP/IP stack for local connections is still wasteful and even with some localhost shortcuts in the system still adds significant overhead. jasonbarnabe.wordpress.com/2014/10/01/…Leblanc

© 2022 - 2024 — McMap. All rights reserved.