Assuming the following:
- Team A is where your MySQL engine runs.
- Team B is where your Java application that wants to communicate with the database runs.
The first thing to consider is that the teams (known from now as teams A and B) can communicate. That is, at least you should check that you can do ping
to A from B.
In the connection string, you must indicate the name of server A to know it in the network, or in its defect the ip to get to the server. The value would be something like this:
String url = "jdbc:mysql://nombreEquipoA:3306/bdaconectarme";
As you can see, <nombreEquipoA>
can be:
- In case A and B are in the same LAN or WAN:
- Hostname of team A (eg server-mysql). An example is the name you can access using
\servidor-mysql
.
- Device A IP (eg 192.168.1.2 or 10.3.50.10)
- In case A and B are not in the same LAN or WAN but can communicate over the internet (eg cloud services):
- Hostname of team A (eg mysqlserver.misubdomain.mydomain.com)
- Public IP that allows the server to exit to the internet.
Examples:
String url = "jdbc:mysql://192.168.1.2:3306/bdaconectarme";
String url = "jdbc:mysql://servidor-mysql:3306/bdaconectarme";
//ojo, IP de abajo puesta arbitrariamente por motivos de ejemplo
//no soy responsable del contenido a encontrar en dicha IP
String url = "jdbc:mysql://193.17.49.12:3306/bdaconectarme";
String url = "jdbc:mysql://servidor.enlanube.com:3306/bdaconectarme";