Connect to mysql database with R on virtual server with private key

82 Views Asked by At

I want to connect to a mysql database with R. I have always used the RMySQL package. Unfortunately, you need SSH authentication on the current server with a private rsa key. Is there a way to connect directly or by using the ssh package to the database with the private key via R? Many thanks for the support

I tried to connect with the ssh package to the server.

library(RMySQL)
library(ssh)

session <- ssh_connect(host = '[email protected]', keyfile = 'user_rsa')

this was succesfull, now I'd like to connect to the mysql database on this server.

mydb = dbConnect(MySQL(), user='db_user', password='db_password', dbname='dbname', host='session')

I get the following message:
Error in .local(drv, ...) :
Failed to connect to database: Error: Unknown server host 'session' (11001)

How could I use the ssh connection to connect to the mysql database on the server?

0

There are 0 best solutions below