Connecting to MySql database with SSH tunneling on remote host with specific mysql host

I know this is old, but the localSSHUrl is really the host that you would use when you are logged in to SSH.

In short, this is usually “localhost” when you are trying to connect to databases as a local user.

int assigned_port = session.setPortForwardingL(localPort, “localhost”, remotePort);

Many examples use remote_host to connect both to the SSH and to the database via port forwarding, but if you only have local access to the database, it will fail to connect.


Well it was wrong way of port forwarding that was the root cause of the problem:

instead of:

int assinged_port = session.setPortForwardingL(localPort, remoteHost, remotePort);

it should have been

int assinged_port = session.setPortForwardingL(localPort, localSSHUrl, remotePort);

The connection runs fine now.