简体   繁体   English

如何将SQL数据库连接到Internet?

[英]How Do I Connect SQL Database to Internet?

I have a small program that I made with Java and intend to have it run on any computer that it is downloaded to. 我有一个用Java编写的小程序,打算在下载到的任何计算机上运行。 Part of this program connects to a MySQL Database that is running on my localhost. 该程序的一部分连接到在我的本地主机上运行的MySQL数据库。 However, since I want this to be able to run smoothly on any computer that is connected to the internet, it is probably necessary that I have my program connect to the database over the internet. 但是,由于我希望它能够在连接到Internet的任何计算机上顺利运行,因此可能有必要让我的程序通过Internet连接到数据库。 Currently, my program connects to the database like this: 当前,我的程序像这样连接到数据库:

Connection con = DriverManager.getConnection("jdbc:mysql://my_public_ip/name_of_database", "user", "user_password");

The user named 'user' for my database has a host of '%', which I understand means any host. 我数据库的名为“ user”的用户的主机为“%”,据我了解,该主机是任何主机。 However, when I run the program on a computer that is connected to a different network than the one mine is connected to, I get a Communications Link Failure. 但是,当我在连接到与一个地雷所连接的网络不同的计算机上运行该程序时,出现通信链接故障。 Just for reference, I use xampp software to administer my database. 仅供参考,我使用xampp软件来管理数据库。 Thanks in advance for any help on this matter. 在此先感谢您的帮助。

You need to make sure your public IP is static, your internal IP is static and port-forwarded on port 3306 and that your firewall allows remote connections to port 3306. 您需要确保公用IP是静态的,内部IP是静态的并且在端口3306上进行端口转发,并且您的防火墙允许远程连接到端口3306。

I wouldn't recommend it though, unless you know exactly what you are doing because opening up a (windows) computer to the internet can be quite dangerous if you make a mistake. 不过,我不建议这样做, 除非您确切地知道自己在做什么,因为如果您犯了一个错误,那么将一台(Windows)计算机打开到互联网可能会非常危险。 There is a reason why (almost) all databases are only reachable by localhost. 有一个原因为什么(几乎)所有数据库只能由localhost访问。

I have a raspberry pi hosted at home and i can say that there is a lot that could go wrong. 我家里有一个树莓派,我可以说有很多地方可能出问题了。 Wrong port forwarding could result in your network being hijacked. 错误的端口转发可能会导致您的网络被劫持。 Wrong IP configurations can result in computer hijacking and reachabillity issues. 错误的IP配置可能导致计算机劫持和可达性问题。 And of course you could get randomly port-scanned and brute-forced on the discovered ports. 当然,您可以在发现的端口上进行随机端口扫描和强行使用。

If you really want to do this i would recommend that you acquire a level of knowledge that allows you to set something like this up without asking for help. 如果您确实想这样做,我建议您获得一定的知识水平,使您无需寻求帮助即可进行类似设置。

If this goes wrong, it can go wrong very, very badly... 如果这出了问题,则可能会非常非常严重地出问题...

您将需要在路由器上设置端口转发,以便在运行mysql数据库的情况下,将通过端口3306进入家庭网络的连接转发到您的计算机。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM