Search code examples
mysqlrsshrstudiorstudio-server

SSH Tunnel from Remote Server to Remote Server (to connect RStudio to MySQL)


I (Local Z) do data analysis on a remote server (Server A), and I need to connect to a database (Database D) on another remote server (Server B).

I can connect to Database D by SSH tunneling to Server B from Local Z.

However, I run RStudio Server on Server A, and I need to connect to Database D within RStudio on Server A.

How can I go about SSH tunneling from Server A to Server B and connecting to MySQL within RStudio?

EDIT: I'm using the RMySQL package to connect to the database within RStudio. Database D also only allows local connections, so SSH tunnel is required.


Solution

  • Solved: after SSH tunneling from my server to the 2nd server, for some reason (if anyone knows, please add a comment), changing 'localhost' to '127.0.0.1' in the R code allowed me to connect (contrary to settings I've used in similar ways for other databases...).