Question

I'm running Sequel Pro 0.9.9.1 and can connect to a remote mySQL (v 14.14) database hosted on a server that only allows SSH connections. When I connect via Sequel Pro, I only need to fill out the ssh user and password to connect without issue. I am able to access all databases in this manner.

I then try to connect to the database in R (2.14.0) using RMySQL (0.9-3), but this command fails:

conn <- dbConnect(MySQL(), user="ssh_user", password="ssh_password", host="localhost")

with the error: "RS-DBI driver: (Failed to connect to database: Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" regardless of if I use single quotes (suggested elsewhere), change the user and/or password to "root" or "", or substitute "127.0.0.1" for "localhost". If I substitute the server host for host in the R command, I am told I cannot access the server (which is true, it is configured to only be accessed via ssh).

What are the correct user, password and host to use to connect to a database accessed via ssh through Sequel Pro in this manner?

Was it helpful?

Solution

I've never done this, but I assume you could use SSH to tunnel the appropriate port, as discussed here: http://www.howtogeek.com/howto/ubuntu/access-your-mysql-server-remotely-over-ssh/ .

In brief, you would:

  1. Tunnel the appropriate port through SSH, which by default would be 3306 for MySQL.
  2. Use dbConnect() to connect to the MySQL server as if it was on your local machine.

This bypasses the need for Sequel Pro. The tunnel essentially allows traffic on your local 3306 port to be tunneled through an SSH connection on port 22 between your local machine and the server and then forwarded to port 3306 locally on the server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top