How to connect to MySQL from another PC?

0

I am new programming in java and I am learning how to use mySQL as well. I can already connect a database recorded on my PC, but I have a question as to how to connect to a database recorded on another computer.

I am using Netbeans ..... as I am new to this programming, I would appreciate if your answers were in a simple language and not so technical.

    
asked by Paul Julio 16.07.2017 в 00:15
source

1 answer

1

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";
    
answered by 16.07.2017 в 00:23