【发布时间】:2014-06-24 10:53:36
【问题描述】:
在问之前我先读过这个: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
我错过了什么,我应该去哪里看?
【问题讨论】:
-
客户端的IP/掩码是什么?啊,现在我知道您只使用一台机器
-
它是本地的(远程 ssh 并从 linux 命令行启动 mysql)
标签: mysql connection