Skip to content
Prev 132472 / 398506 Next

connecting [logging] RMySQL to an external server - SOLVED

On Saturday 15 December 2007, Gabor Grothendieck wrote:
For those interested in using R with a remote MySQL database, here's the most 
simple and straightforward solution (thanks to Gabor):

On the console, forward local port 3307 to remote port 3306
ssh -L 3307:xxx.xxx.xxx.xxx:3306 myuser at xxx.xxx.xxx.xxx

(where xxx.xxx.xxx.xxx is the IP of the remote server and myuser is the login 
name). After entering the password, keep that console open.

In R:

library(RMySQL)
drv <- dbDriver("MySQL")
dbConnect(drv, user="mysqluser", password="mysqlpassword", 
dbname="anydatabase", host="127.0.0.1", port="3307")

(where mysqluser and mysqlpassword are the remote machine's MySQL username and 
password).

Another possible solution is suggested by Prof. Ripley, using stunnel to 
create a secure tunnel between the local and the remote machines, but I 
haven't explored that in detail.


Best wishes,
Adrian