简体   繁体   中英

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. Part of this program connects to a MySQL Database that is running on my localhost. 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. 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. 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. 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.

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. There is a reason why (almost) all databases are only reachable by 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. 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进入家庭网络的连接转发到您的计算机。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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