3

我正在尝试通过192.168.1.5使用 NetBeans 从 Java 使用 MySQL 数据库(安装在我的电脑上的虚拟机(Debian)上并具有 IP 地址)。

我已将连接配置如下:

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这不是很安全,但这只是为了暂时简化事情):

+------------+------------------+
| host       | user             |
+------------+------------------+
| %          | root             |
| 127.0.0.1  | root             |
| ::1        | root             |
| debVirtual |                  |
| localhost  |                  |
| localhost  | debian-sys-maint |
| localhost  | phpmyadmin       |
| localhost  | root             |
+------------+------------------+

我该怎么做才能允许这种连接?

4

4 回答 4

5

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

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

bind-address = 192.168.1.5

并不是

bind-address = 127.0.0.1

允许远程访问。

于 2012-05-12T20:30:11.903 回答
0

你可以发布你的整个代码吗?

当您尝试访问的数据库不存在时,就会出现该错误。检查 VM 软件中的网络设置。您使用的是什么类型的 VM 软件(VirtualBox、VM ware...)

于 2012-05-12T20:27:38.613 回答
0

这是错误的文件夹,或者我有不同的版本。我正在运行 Lubuntu,但文件不是 my.cnf(因为该文件没有绑定地址)。绑定地址位于/etc/mysql/mysql.conf.d/名称为的文件中:mysqld.cnf. 您无法通过文件管理器对其进行修改,因此您必须通过以下命令行:

sudo su
***enter password***
cd /etc/mysql/mysql.conf.d
nano mysqld.cnf

然后转到 bind-address 127.0.0.1 并将其更改为您可以在其中找到的 IPv4

ifconfig

我希望我有所帮助。

于 2016-05-26T16:27:32.630 回答
-1

完美解决方案:

  1. 在 netbeans 之前启动 wamp 服务器
  2. 然后打开netbeans

它对我有用。当我关闭 wamp 服务器时,它向我显示此错误:

于 2015-12-20T17:09:58.577 回答