December, 2012

Connecting R to a MySQL database in a remote machine

Today I devoted a significant amount of time to solve a problem which seemed simple to me. I wanted to access a MySQL database from R. The database is in a remote machine, web and I wanted to use an ssh tunnel to connect to it. The database is configured so that its local alloweduser user can connect directly to it (no password). To make things more interesting, buy more about I cannot connect directly to the target machine, physiotherapy I have to use an intermediate one to establish the tunnel.

So, again, what I wanted to do was:

  • Open an ssh  tunnel to targethost machine, using intermediatehost (which already has a tunnel to targethost).
  • Use that tunnel to connect to a certain MySQL database in targethost, using the alloweduser account, without using a password.
  • Do all of the above from R.

[Yes, I know many people would object having a connection to a database specifying only a user, with no password. But first, the database only allows connections from localhost, and all local users are trusted. Second, it is a long story… 😉 ]

(more…)

Posted in Debian, Software libre No Comments »