Connect to MySql db over SSH in Netbeans

2019-01-26 02:34发布

问题:

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?

回答1:

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.

I'm not sure what OS your using but, assuming you are using some flavour of Linux here are the steps to take:

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>

You'll be prompted for your SSH password. Enter it.

2) In Netbeans go to Services and set up a new MySQL database connection with the following credentials:

host: 127.0.0.1

username: root (I'm assuming that the remote MySQL db allows remote root connections?)

password: password (I guess you must have a password for the MySQL database that you're connecting to?!)

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!