Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to a remote mysql over ssh tunnel in spring boot application

I have a spring boot application which is using mySQL db.DB is accessible on ssh via a different server.In Mysql Workbench i have created tunnel to access the mysql DB.

Now my question is there any way that i can do the same(tunnel over ssh) in my spring boot application? I have already searched on google but didn't get any fix for it.

If anyone can give an idea how to implement that would be really helpful.

Regards,

like image 614
Manish Avatar asked Mar 05 '23 23:03

Manish


1 Answers

Assuming that you are on a UNIX/Linux platform, the idea is that you do a

ssh -L 3306:mysql-server:3306 username@mysql-server

From within you spring boot application, you do a connect to localhost:3306 which is forwarded to the mysql-server on port 3306.

Doing it directly inside spring boot, you should go with Java Secure Channel. An example for port forwarding is described here.

like image 50
JGK Avatar answered Apr 05 '23 21:04

JGK