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

后端 未结 2 970
小蘑菇
小蘑菇 2021-01-03 04:53

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

I\'m using Netbeans 6.9.1, JPA, MySQL 5.2.

相关标签:
2条回答
  • 2021-01-03 05:31

    You can't ... You have to set up external ssh tunel.

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

    Later change connection-url jdbc:mysql://127.0.0.1:3307/yourdatabase

    0 讨论(0)
  • 2021-01-03 05:32

    I assume you want to tunnel to a remote mysql which only listens to localhost (or is firewalled)

    The easiest way is then

    1. setup a trust relationship between the account running the application server providig the JPA service to your application

    2. create the tunnel using ssh -L 3306:localhost:3306 mysql.server.org to create a tunnel which will connect port 3306 on the appservers host to port 3306 on the mysql server's localhost port.

    3. Configure JPA to connect to localhost:3306

    0 讨论(0)
提交回复
热议问题