Pat*_*ryk 3 java mysql netbeans netbeans-7
我正在尝试使用MySQL数据库(安装在我的电脑上的虚拟机(Debian)上并具有IP地址192.168.1.5)来使用NetBeans.
我已按如下方式配置连接:
Driver Name MySQL(Connector/J Driver)
Host 192.168.1.5
Database test
Username root
Password *
JDBC URL jdbc:mysql://192.168.1.5:3306/test
Run Code Online (Sandbox Code Playgroud)
然后我收到以下错误:
cannot establish a connection to jdbc:mysql://192.168.1.5:3306/test using
com.mysql.jdbc.Driver (Communications link failure The last packet sent successfully
to the server was 0 milliseconds ago. The driver has not received any packets
from the server.)
Run Code Online (Sandbox Code Playgroud)
我的mysql.user表看起来像这样(我知道% root这不是很安全,但这只是为了简化目前的事情):
+------------+------------------+
| host | user |
+------------+------------------+
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| debVirtual | |
| localhost | |
| localhost | debian-sys-maint |
| localhost | phpmyadmin |
| localhost | root |
+------------+------------------+
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能允许这种连接?
问题出在服务器上的mysql配置文件中 /etc/mysql/my.cnf
该行:bind-address 应该指向您的服务器的IP,如本例所示
bind-address = 192.168.1.5
并不是
bind-address = 127.0.0.1
允许远程访问.