且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过 SSH 和使用 Spring Boot 连接到 MySQL

更新时间:2023-01-20 08:05:09

我不认为 spring 可以为您创建 SSH 隧道,如果这就是您正在寻找的.如果要在代码中做,就需要jsch这样的框架.

I don't think spring can create a SSH tunnel for you if that's what you're looking for. If you want to do it in the code, you need a framework like jsch.

***的解决方案是在服务器上手动或使用 autossh(以保持运行)创建 SSH 隧道.要手动创建隧道,请登录到您的应用服务器并在屏幕中运行以下命令:

The best solution would be to create the SSH tunnel on the server manually or by using autossh (to keep it up). To create a tunnel manually, log on to your app server and run this command in a screen:

ssh -L 3307:localhost:3306 serverIp

3306 是运行 mysql 的端口.3307 是您要转发的端口.使用此隧道,您现在可以使用以下方式进行连接:

3306 is the port mysql is running on. 3307 is the port you are forwarding. With this tunnel you can now connect by using:

spring.datasource.url=jdbc:mysql://localhost:3307/