java 远程 MYSQL 数据库访问

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1700518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 17:39:59  来源:igfitidea点击:

Remote MYSQL Database Access

javamysql

提问by Mayan Alagar Pandi

I have developed an application in java that access remote mysql database. While I am running it by netbeans IDE of system which have running that wamp server. But while i try I make connection in another system to remote system database by netbeans it shows following error.

我在java中开发了一个访问远程mysql数据库的应用程序。当我通过运行该 wamp 服务器的系统的 netbeans IDE 运行它时。但是当我尝试通过 netbeans 在另一个系统中连接到远程系统数据库时,它显示以下错误。

Unable to add connection, Cannot establish a connection to jdbc:mysql://192.168.1.14:3306/test using(CommunicationsException: Communications link failure

无法添加连接,无法与 jdbc:mysql://192.168.1.14:3306/test using(CommunicationsException: Communications link failure)建立连接

Last packet sent to the server was 0 ms ago.

发送到服务器的最后一个数据包是 0 毫秒前。

Please, kindly help me.

请帮助我。

Thanks in Advance

提前致谢

回答by Peter Lindqvist

From mysql forums

来自mysql 论坛

You could be getting this because (1) the URL of the DB is wrong, because (2) the DB isn't set up to accept connections from the web host, or because (3) some intermediate networking component is misconfigured. (1) is your problem; (2) and (3) might be your problem or the web hosting's problem, depending on where the DB is located, what administrative privileges on the DB that you have, and how the networking is set up.

您收到此消息可能是因为 (1) 数据库的 URL 错误,因为 (2) 未将数据库设置为接受来自 Web 主机的连接,或者因为 (3) 某些中间网络组件配置错误。(1) 是你的问题;(2) 和 (3) 可能是您的问题或网络托管的问题,具体取决于数据库所在的位置、您拥有的数据库管理权限以及网络的设置方式。

You need to have the right privileges to be able to connect to MySQL remotely. There are several tools available to set it up.

您需要拥有正确的权限才能远程连接到 MySQL。有多种工具可用于设置。

Hereis an article outlining several steps of which the grant step is most commonly needed.

是一篇文章,概述了最常需要授予步骤的几个步骤。

mysql> GRANT ALL ON foo.* TO bar@'202.54.10.20' IDENTIFIED BY 'PASSWORD';

There has also been problems reported when connecting to MySQL databases in Windows Vista, but i'm not sure wether this is relevant to this case or not.

在 Windows Vista 中连接到 MySQL 数据库时也报告了一些问题,但我不确定这是否与这种情况有关。

回答by hennings

Do you have ssh access to the server? I would have run a tunnel with ssh, plink or putty (ssh -L 3305:127.0.0.1:3306 192.168.1.14) and then use this connection url

您是否可以通过 ssh 访问服务器?我会使用 ssh、plink 或 putty (ssh -L 3305:127.0.0.1:3306 192.168.1.14) 运行隧道,然后使用此连接 url

jdbc:mysql://127.0.0.1:3305/test

It would be easier to assist if we'd known your operating system.

如果我们知道您的操作系统,会更容易提供帮助。

If this is a deployment situation, opening the firewall for port 3306 from your IP address is probably the right thing. In linux you might find the settings in /etc/sysconfig/iptables, but your sysadmin may have other safe guards in place. You must also verify that mysql is actually listening on the IP-address, and not only localhost.

如果这是部署情况,从您的 IP 地址打开端口 3306 的防火墙可能是正确的做法。在 linux 中,您可能会在 /etc/sysconfig/iptables 中找到这些设置,但您的系统管理员可能有其他安全措施。您还必须验证 mysql 实际上正在侦听 IP 地址,而不仅仅是 localhost。

回答by hennings

MySQL is standard protected so you can't access it remotely. You'll have to grant MySQL as well as the user connecting to MySQL access from outside the MySQL-machine.

MySQL 受标准保护,因此您无法远程访问它。您必须授予 MySQL 以及从 MySQL 机器外部连接到 MySQL 的用户的访问权限。

回答by Brian Agnew

Perhaps a low-level network issue.

可能是低级网络问题。

Can you ping that IP ? Can you telnet to that IP/port ?

你能ping通那个IP吗?你能 telnet 到那个 IP/端口吗?

e.g. telnet 192.168.1.14 3306

例如 telnet 192.168.1.14 3306

Establishing whether you can talk to the machine and whether you can create a basic TCP connection to the MySQL process on that machine will tell you a lot - is your network sound, is a process listening on that port etc.

确定您是否可以与机器对话以及您是否可以在该机器上创建到 MySQL 进程的基本 TCP 连接会告诉您很多信息 - 您的网络是否正常,是否有进程正在侦听该端口等。