I want to connect to MySQL database through bastion host.
I followed some previous StackOverflow answers and I am able to establish connection through the terminal (in RStudio) :
ssh -i <path_to_key_file> <username>@<bastion_host> -L 3306:<db_host>:3306
Then from R:
library(RMySQL)
m <- dbDriver("MySQL")
con <- dbConnect(
m,
user='<db_username>',
password='<db_password>',
host='127.0.0.1',
dbname='<db_name>',
port=3306
)
dbGetQuery(con, "SHOW TABLES;")
dbDisconnect(con)
But now, how can I establish connection directly from the R
code, so I don't have to ssh in the terminal? I know library(ssh)
might be helpful here but I can't figure out how to make it working.
Thanks!