MySQL-可以通过本地主机连接,但不能通过127.0.0.1

时间:2018-09-12 21:28:01

标签: mysql

我有一个在Debian(Server version: 5.5.60-0+deb8u1 (Debian))上运行的MySQL服务器。一切正常,直到重新启动服务器。现在,我只能通过localhost连接到我的MySQL服务器,而通过127.0.0.1无法使用:

$ mysql -h 127.0.0.1 -u root -p给了我ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

我在防火墙中打开了端口3306,服务器似乎正在侦听3306:

$ netstat -plnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State        PID/Program name
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN       20877/mysqld

使用telnet连接到3306似乎无效,(对于localhost和127.0.0.1而言):

$ telnet 127.0.0.1 3306
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

在我的my.cnf中,我有bind-address = 127.0.0.1,这应该不是问题...

/etc/hosts中有以下几行

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback

我只是找不到错误,您有什么主意吗?

1 个答案:

答案 0 :(得分:1)

事实证明,TCP-Wrappers拒绝与127.0.0.1的连接。通过将mysqld: 127.0.0.1添加到/etc/hosts.allow文件中来解决。

相关问题