为什么在使用 Java (Netbeans) 连接到 MySQL 时会收到此错误“通信链接失败最后一个数据包发送..."? [英] Why I get this error 'Communications link failure The last packet sent...' when connecting to MySQL with Java (Netbeans)?

查看:23
本文介绍了为什么在使用 Java (Netbeans) 连接到 MySQL 时会收到此错误“通信链接失败最后一个数据包发送..."?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 NetBeans 从 Java 使用 MySQL 数据库(安装在我电脑上的虚拟机 (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 ?

推荐答案

问题出在服务器上的mysql配置文件/etc/mysql/my.cnf

The problem was with mysql configuration file on the server /etc/mysql/my.cnf

行:bind-address 应该指向你的服务器的 IP,就像这个例子中的

the line : bind-address should point to your server's IP like in this example

绑定地址 = 192.168.1.5

而不是

绑定地址 = 127.0.0.1

允许远程访问.

这篇关于为什么在使用 Java (Netbeans) 连接到 MySQL 时会收到此错误“通信链接失败最后一个数据包发送..."?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆