大网数据广告活动
服务器运维问答

Postfix can't connect to MariaDB on 127.0.0.1

· 52CE 我爱测

(Yes, this question seems very similar , but I understand why I get the message. What I don't get, and can't find any palpable information about on my own, is what to do about it. So here I am.) I am trying to set up Postfix and …

问题原文

原帖链接 · Aurora Vollvik · CC BY-SA 3.0

(Yes, this question seems very similar, but I understand why I get the message. What I don't get, and can't find any palpable information about on my own, is what to do about it. So here I am.)


I am trying to set up Postfix and Dovecot on my VPS, deciding to go the MySQL-route with MariaDB. Following this guide, which seems pretty okay.

Got as far as to test the DB config files with postmap, when the server simply refused connection. This is the error message I get;

postmap: warning: connect to mysql server 127.0.0.1: Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")
postmap: fatal: table mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf: query error: Transport endpoint is not connected

MariaDB's config file is set up to bind with 127.0.0.1, I opened 3306 for 127.0.0.1 and even tried disabling the firewall altogether without any change.

It seems that the IP and port can't be to blame then, and I assume this "Transport endpoint" must be the culprit - if that's not just another way of referring to the IP/port.

If anyone has suggestions as to what I can try to get around this, I would be incredibly grateful.

Edit: If it makes any difference, I'm using nginx as well.

Edit II: Results of 'service mysql status':

* /usr/bin/mysqladmin  Ver 9.1 Distrib 10.1.11-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Server version          10.1.11-MariaDB-1~trusty-log
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/run/mysqld/mysqld.sock
Uptime:                 2 hours 37 min 16 sec

已采纳解答

原帖链接 · Aurora Vollvik · CC BY-SA 3.0

I found the answer here, after HBruijn set me on the right path: https://mariadb.com/kb/en/mariadb/configuring-mariadb-for-remote-client-access/

MariaDB has the skip-networking directive active as default, which stops all TCP/IP connections. After commenting it out, but leaving bind-address as is I let MariaDB listen to TCP on the default port (3306) only for local connections.

Change this in my.cnf:

#skip-networking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1

Restarted the mysql service and tested to see what ports were listened on;

# netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
..some records..
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN

Also successfully logged into MariaDB through 127.0.0.1, and everything works! Yay!

# mysql -u mailuser -h 127.0.0.1 -D mailserver -p
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 49
Server version: 10.1.11-MariaDB-1~trusty-log mariadb.org binary distribution

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [mailserver]>It finally works!

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-31)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。