R - 在 R 中使用 VPN 连接到 MySQL

R - Connect to MySQL using VPN in R

我想 运行 依赖需要 VPN 的 MySQL 连接的远程服务器上的 R 脚本。我使用 Cisco VPN 客户端在我的本地计算机上执行此操作。

对于需要 VPN 的 R 应用程序,是否有任何方法可以促进 MySQL 连接?

更具体地说,我有兴趣促进 knitr 脚本在远程服务器上生成 html 或在远程服务器上部署我闪亮的应用程序,但对于两者我都需要 MySQL 通过 VPN 向服务器查询 运行。对此过程或解决方法的任何想法将不胜感激。

感谢您的帮助。

您或许可以使用 PuTTY 连接到 vpn。这是通过 MS Windows 7/8 ***一旦通过 PuTTY 连接,就可以连接到 MySQL:

YourvpnDB <- dbConnect(
MySQL() 
, user="enter your database user name here" 
, password=" enter your database password here " 
, db=" enter the name of your database here " 
, host="127.0.0.1" )

我没试过,但理论上应该可行:)

提问后时间已经过去了,但我找到了解决这个问题或类似问题的方法。要连接到我的数据库,我需要通过 VPN 来完成,而我不需要 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)

这样我就可以在任务调度器中自动执行脚本