How to connect to a remote MySQL server via SSH using JPA?

I am trying to connect to a remote MySQL server via SSH in my Java project. How to integrate SSH connection with JPA?

I am using Netbeans 6.9.1, JPA, MySQL 5.2.

+4
source share
2 answers

I assume you want to tunnel a remote mysql that only listens on localhost (or is a firewall)

The easiest way is

  • establish trust between the account on which the application server is running, will provide JPA service to your application

  • create a tunnel using ssh -L 3306:localhost:3306 mysql.server.org to create a tunnel that will connect port 3306 on the appservers host to port 3306 on the localhost port of mysql server.

  • Configure JPA to connect to localhost:3306

+4
source

You cannot ... You need to configure an external ssh tunnel.

 ssh -N -f -L 3307:localhost:3306 login@remotwhostwithmysql 

Late JDBC connection-url change: MySQL: //127.0.0.1: 3307 / yourdatabase

+3
source

All Articles