I have the following problem.
Background:
- I want to connect to a MySQL database and download tables into R.
- The database (the MySQL prompt) can only be accessed via SSH tunnel to another server.
- I am using Mac OSX El Capitan on a MacBook Pro (2015).
Problem:
From the 'terminal', I can easily SSH to the server, and thereon enter the MySQL prompt and run the queries I need.
I cannot, however, perform the latter tasks from within RStudio.
The code I tried is:
> system('ssh -f <server_user>@<server_ip> -N sleep 20')
> db <- dbConnect(MySQL(), host="hostname", user="username", pwd="password", dbname="databasename", port=3306)
> sql1 <- paste("SELECT * FROM databasename.tablename", sep="")
> results <- dbGetQuery(con, sql1)
> dbDisconnect(con)
While I can see from ps -A | grep ssh that the ssh process is running (for the 20 seconds I want it to), and in R the command executed normally (not waiting for more input), I cannot connect to the relevant database. The error message was something to effect of "could not connect", and RStudio hangs for at least a minute before the error appears.
The questions:
How does one (1) Use SSH in conjunction with (2) MySQL on the remote server to (3) load tables directly into an R data frame?
Thanks.