-1

There's a way to make a MySQL with XAMPP go online to connect by Mobile Data (Android app) or PC app without beeing on the same local area connection?

This are the specs of the PC where XAMPP is running:

  • 16GB RAM
  • i7-8700
  • SSD - 512GB
  • Integrated GPU
  • 100MB Internet Connection (Optical Fiber)

What im tying to do is connect to the DB without beeing on the same connection as the PC where XAMPP is on execution,something like open the Android app on California meanwhile the PC is on Baja California

  • Possible duplicate of [How to allow remote connection to mysql](https://stackoverflow.com/questions/14779104/how-to-allow-remote-connection-to-mysql) – Igor Jul 18 '19 at 23:15
  • 1
    Follow https://stackoverflow.com/questions/14779104/how-to-allow-remote-connection-to-mysql and remember to forward your MySQL-port (3306 by default) accordingly. **However:** I would consider this bad practice (even if you restrict only certain DB-users to certain DBs etc.), because you have to keep track of MySQL vulnerabilities. I would suggest to have your mobile app communicate with some sort of "backend", which then accesses the database. While the backend would be visible to users (and potential attackers), the database would not. – Igor Jul 18 '19 at 23:18

1 Answers1

0

The problem is that your PC is most likely sitting behind a router. The router maps multiple private IP addresses to one public IP address. How does it do that? It uses NAT. In very basic terms, when a device D1 (say with private ip 192.168.1.10), sits behind a router and wants to communicate with a public device D2, it sends a request. The request goes to the router. The router adds the public IP address and an arbitrary port (e.g. 12345) to the packet. The router keeps a table with all ports linked with the private devices (e.g. 192.168.1.10 -> 12345, ...). Then it sends the packet to D2 using D2's public IP address. D2 sends a response back to the router public IP. The router forwards the packet to the private device using the port number and the table, in this case the device is D1.

So, you can't directly communicate with a device sitting behind a router from outside the router. However, you can use port forwarding. You can tell the router to always map a specific port to a specific private IP (your PC's IP). Then, you make the other deivce (your Android app) communicate with it using that port.

In summary, if we have two devices, A and B, and A is behind a router. If A wants to initiate a connection with B, then:

  • if B is behind the same router, then they can use their private IP addresses.

  • if B is not behind any router, then A can communicate with it using B's public IP address, as demonstrated above.

  • If B is behind a different router, then there must be some kind of port forwarding.
3li
  • 598
  • 3
  • 13