SSH的java.sql.Connection扩展 [英] java.sql.Connection extension for SSH

查看:145
本文介绍了SSH的java.sql.Connection扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在防火墙后面有一个MySQL数据库,只能通过SSH连接访问。有没有人知道java.sql.Connection的实现,它允许我与这个数据库建立SSH连接?

I have a MySQL database behind a firewall which can only be accessed via an SSH connection. Does anyone know of an implementation of java.sql.Connection which would allow me to make an SSH connection to this database?

推荐答案

您可以使用SSH的端口转发来执行此操作。虽然不是纯java.sql.Connection,但它允许您通过ssh隧道连接。

You can use SSH's port forwarding to do this. While not a pure java.sql.Connection, it will allow you to tunnel the connection through ssh.

ssh -L 3306:localhost:3306 remote.mysql.host.com

这会将本地计算机上的端口3306转发到remote.mysql.host.com上的端口3306。这将允许您连接到本地计算机上的端口3306,它将被隧道传输到remote.mysql.host.com。

This will forward port 3306 on your local machine to port 3306 on remote.mysql.host.com. This will allow you to connect to port 3306 on your local machine, and it will be tunnelled to remote.mysql.host.com.

如果您要查找在Java中,使用 JSch 创建ssh连接。

If you're looking to do it all in Java, create the ssh connection with JSch.

这篇关于SSH的java.sql.Connection扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆