简体   繁体   中英

Access the database from outside using a SSH tunnel Fortrabbit

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 u-my-app@ssh2.eu1.frbit.com

在此处输入图片说明

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM