Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - Connect to MySQL using VPN in R

Tags:

mysql

r

vpn

I want to run an R script on a remote server that depends on a MySQL connection that requires VPN. I do this on my local machine using a Cisco VPN client.

Is there any way to facilitate a MySQL connection for an R application where VPN is required?

More specifically, I'm interested in facilitating either a knitr script to produce html on the remote server or to deploy my shiny app on the remote server, but for both I would need the MySQL queries to run against a server via VPN. Any thoughts on this process or work-arounds would be greatly appreciated.

Thanks for your help.

like image 909
Super_John Avatar asked Oct 28 '25 08:10

Super_John


1 Answers

Time has passed since asked but I found a solution to this or a similar problem. To connect to my database I need to do it via a VPN that I don't need to be connected 24/7.

cmd <- unname(Sys.which("rasdial"))
cmd_args <- c('"VPN NAME"', userID, pass)
system2(command = cmd, args= cmd_args)

con <- dbConnect(odbc::odbc(), ... )
# Do your stuff

# Close the connection
cmd_args <- c('"VPN NAME"', '/DISCONNECT')
system2(command = cmd, args= cmd_args)

In this way I can automate the script in the task scheduler

like image 187
AleRuete Avatar answered Oct 30 '25 00:10

AleRuete



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!