我在 Win7 上运行 VirtualBox 4.2.16。我在 CentOS 6.4 中有 MySQL 服务器。从 Win7 Telnet 到 CentOS 没问题。
mysql -u root -h 192.168.56.102 -p
在 CentOS 中很好。
这是我在用户表中的内容:
mysql> select user, host from user;
+------+----------------+
| user | host |
+------+----------------+
| mm | 127.0.0.1 |
| root | 127.0.0.1 |
| mm | 192.168.56.102 |
| root | 192.168.56.102 |
| mm | localhost |
| root | localhost |
+------+----------------+
6 rows in set (0.00 sec)
MySQL status:
mysql Ver 14.14 Distrib 5.6.13, for Linux (x86_64) using EditLine wrapper
Connection id: 14
Current database:
Current user: root@loc
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.6.13-log MySQL Community Server (GPL)
Protocol version: 10
Connection: 192.168.56.102 via TCP/IP
/usr/my.cnf:
[mysqld]
log_bin
port = 3306
bind-address = 192.168.56.102
/etc/hosts:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.56.102 loc
尽管如此,当我尝试从 Win7/HeidiSQL 连接到 192.168.56.102 端口 3306 上的 root 时,我得到了
SQL 错误 (1130)... 不允许主机 '192.168.56.1' 连接到此 MySQL 服务器。
CentOS 防火墙已关闭,但据我了解,这不是防火墙问题...有什么想法吗?
经过一番研究,我解决了这个问题。在用户表中,每个用户都有 3 个条目:主机 %、主机 localhost、主机 192.168.56.101
这是通过命令 GRANT ALL ON 实现的。TO root@'X' 由带有 GRANT 选项的“pass”标识;
其中 X = %,本地主机,192.168.56.101
这样来宾 MySQL 服务器既可以从来宾也可以从 Win7 主机连接。