为什么在使用Java(Netbeans)连接到MySQL时出现此错误“通信链接失败,最后一个数据包已发送..."? [英] Why I get this error 'Communications link failure The last packet sent...' when connecting to MySQL with Java (Netbeans)?
问题描述
我试图通过NetBeans使用Java的MySQL数据库(安装在我的PC上的虚拟机(Debian)上,并具有IP地址192.168.1.5
).
I am trying to use MySQL database (that is installed on virtual machine (Debian) on my pc and has IP address 192.168.1.5
) from Java with use of 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
然后出现以下错误:
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.)
我的mysql.user
表如下所示(我知道% root
并不是很安全,但这只是为了简化当前操作):
My mysql.user
table looks like this ( I know % root
is not very secure but this is just to simplify things for the moment):
+------------+------------------+
| host | user |
+------------+------------------+
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| debVirtual | |
| localhost | |
| localhost | debian-sys-maint |
| localhost | phpmyadmin |
| localhost | root |
+------------+------------------+
我该怎么做才能允许此连接?
What can I do to allow this connection ?
推荐答案
问题出在服务器/etc/mysql/my.cnf
该行:bind-address
应该指向服务器的IP,如本例所示
the line : bind-address
should point to your server's IP like in this example
bind-address = 192.168.1.5
而不是
bind-address = 127.0.0.1
允许远程访问.
这篇关于为什么在使用Java(Netbeans)连接到MySQL时出现此错误“通信链接失败,最后一个数据包已发送..."?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!