IPTables:连接被MySQL拒绝(10061)

时间:2014-06-24 10:53:37

标签: mysql connection

在问我之前先读过这篇文章:http://dev.mysql.com/doc/refman/5.0/fr/access-denied.html 首先尝试:

~# mysql -h 127.0.0.1 -P 3306 -u uu DBNAME -p
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 3296
Server version: 5.5.37-MariaDB-1~wheezy-log mariadb.org binary distribution

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

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

MariaDB [DBNAME]> Bye

~# mysql -h 127.0.0.1 -P 3307 -u uu DBNAME -p
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

所以它正在侦听端口3306.现在让我们看看我的网络配置:

~# ifconfig
eth0      Link encap:Ethernet  HWaddr d4:ae:52:cd:71:d6
          inet addr:62.210.129.132  Bcast:62.210.129.255  Mask:255.255.255.0
blabla

~#

所以让我们试试正确的工作端口,但不是127.0.0.1:

~# mysql -h 62.210.129.132 -P 3306 -u uu DBNAME -p
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

所以我试图用以下方法修复它:

MariaDB [DBNAME]> GRANT ALL PRIVILEGES ON DBNAME TO 'uu'@'62.%' IDENTIFIED BY 'XX';
Query OK, 0 rows affected (0.00 sec)

MariaDB [DBNAME]> GRANT ALL PRIVILEGES ON DBNAME.* TO 'uu'@'62.%' IDENTIFIED BY 'XX';
Query OK, 0 rows affected (0.00 sec)

MariaDB [DBNAME]> Bye
~# mysql -h 62.210.129.132 -u uu DBNAME -p
ERROR 2003 (HY000): Can't connect to MySQL server on '62.210.129.132' (111)
~#

~# mysql -h 127.0.0.1 -u uu DBNAME -p
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

... blabla

我也检查了表用户:

MariaDB [mysql]> select user, host, password from user;
+------------------+----------------+--------------------+
| user             | host           | password           |
+------------------+----------------+--------------------+
| [skipping root ]                                       |
| uu               | localhost      | *C5E430FB96FF191AF |
| uu               | 62.210.129.132 | *C5E430FB96FF191AF |
| uu               | 62.%           | *C5E430FB96FF191AF |
+------------------+----------------+--------------------+
9 rows in set (0.00 sec)

MariaDB [mysql]>

所以不行。所以我想知道它是来自我的IP策略还是来自mysql服务器策略。这是iptables政策:

Chain PREROUTING (policy ACCEPT 1143 packets, 131K bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain INPUT (policy ACCEPT 56 packets, 2938 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 236 packets, 17506 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 236 packets, 17506 bytes)
 pkts bytes target     prot opt in     out     source               destination
Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    1   211 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    0     0 ACCEPT     tcp  --  eth0   *       62.210.129.132       0.0.0.0/0
    0     0 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80
    0     0 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0            tcp dpt:443
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 3 packets, 852 bytes)
 pkts bytes target     prot opt in     out     source               destination

我错过了什么,我应该在哪里看?

1 个答案:

答案 0 :(得分:0)

感谢this question,我找到了解决方案。 原来我只需要在我的bind-address文件中评论my.cnf指令:

#bind-address       = 127.0.0.1

然后它有效。