Access the database from outside using a SSH tunnel Fortrabbit

200 Views Asked by At

I copy command from form Fortrabbit to access my database using a SSH tunnel:

#Access the database from outside using a SSH tunnel
ssh -N -L 13306:myapp.mysql.eu1.frbit.com:3306 [email protected]

enter image description here

I entered my passphrase. But when I hit enter nothing happens.
Could anyone help?

2

There are 2 best solutions below

0
On

That nothing seems to happen is a good sign:

The connection seems established, and you can, in a separate terminal window, use that existing connection for your mysql work.

See also the fortrabbit tutorial on mysql connection:

https://help.fortrabbit.com/mysql

0
On

You have set up a port forwarding from your localhost:3306 to remoteport:3306.
What this means is the mysql database runinng on remote machine is now accessible at your localhost port 3306.

You can connect it using

Shell

mysql -u <username> -p<password> --host=127.0.0.1 --port=3306

JDBC

String url = "jdbc:mysql://localhost/<db_name>";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Connection conn = DriverManager.getConnection (url, "username", "password");

This will only work as long as the SSh session opened previosly is alive.