在 Netbeans 中通过 SSH 连接到 MySql 数据库
在 Netbeans 中,我需要通过 SSH 创建到远程 MySql 数据库的连接.我得到了 SSH 主机名、SSH 用户名、SSH 密码、MySql 主机名 (127.0.0.1) 和 MySql 用户名 (root).在新的连接向导中,由于涉及 ssh,我不确定该怎么做.我的 JDBC Url 应该是什么样子的?甚至可以从 gui 向导中实现这一点吗?
In Netbeans, I need to create a connection to a remote MySql database over SSH. I am given SSH hostname, SSH username, SSH password, MySql hostname (127.0.0.1) and MySql username (root). In a new Connection Wizard I am not sure what to do since there is ssh involved. How should my JDBC Url look like? Is it even possible to achieve this from a gui wizard?
推荐答案
嗯.我认为最好的方法是在尝试通过 NetBeans 连接到远程数据库之前设置端口转发.
Hmm. I reckon the best way for you to do this is to set up port forwarding before attempting to connect to your remote database via NetBeans.
我不确定您使用的是什么操作系统,但是,假设您使用的是某种 Linux 版本,以下是要采取的步骤:
I'm not sure what OS your using but, assuming you are using some flavour of Linux here are the steps to take:
1) 将本地端口转发到远程 MySQL 数据库服务器打开终端窗口并输入:
1) Forward a local port to your remote MySQL Database server Open up a terminal window and type:
sudo ssh -L 6666:127.0.0.1:3306 <your_SSH_username<@<remoteserver.com>
系统会提示您输入 SSH 密码.输入它.
You'll be prompted for your SSH password. Enter it.
2) 在 Netbeans 中,转到服务并使用以下凭据设置新的 MySQL 数据库连接:
2) In Netbeans go to Services and set up a new MySQL database connection with the following credentials:
主机:127.0.0.1
用户名:root(我假设远程 MySQL 数据库允许远程 root 连接?)
username: root (I'm assuming that the remote MySQL db allows remote root connections?)
password:密码(我猜你一定有你要连接的 MySQL 数据库的密码?!)
password: password (I guess you must have a password for the MySQL database that you're connecting to?!)
jdbc url 应该是这样的:
The jdbc url should look something like this:
jdbc:mysql://127.0.0.1:6666?username=root&password=<your_remote_db_root_password>
这里有一篇很好的帖子了解更多有关端口转发/隧道的详细信息.
There's a good post here for more details on port fowarding/tunnelling.
祝你好运,我希望这会有所帮助!
Good luck and I hope this helps!
相关文章