rafter mysql_通过SSH建立隧道后,在R(RStudio)中访问MySQL数据库

bd96500e110b49cbb3cd949968f18be7.png

I have the following problem.

Background:

I want to connect to a MySQL database and download tables into R.

The database (the MySQL prompt) can only be accessed via SSH tunnel to another server.

I am using Mac OSX El Capitan on a MacBook Pro (2015).

Problem:

From the 'terminal', I can easily SSH to the server, and thereon enter the MySQL prompt and run the queries I need.

I cannot, however, perform the latter tasks from within RStudio.

The code I tried is:

> system('ssh -f @ -N sleep 20')

> db

> sql1

> results

> dbDisconnect(con)

While I can see from ps -A | grep ssh that the ssh process is running (for the 20 seconds I want it to), and in R the command executed normally (not waiting for more input), I cannot connect to the relevant database. The error message was something to effect of "could not connect", and RStudio hangs for at least a minute before the error appears.

The questions:

How does one

(1) Use SSH in conjunction with

(2) MySQL on the remote server to

(3) load tables directly into an R data frame?

Thanks.

解决方案

You should use something which is called port forwarding. Some details are here (https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding)

For example, say you wanted to connect from your laptop to http://www.ubuntuforums.org using an SSH tunnel. You would use source port number 8080 (the alternate http port), destination port 80 (the http port), and destination server www.ubuntuforums.org. :

ssh -L 8080:www.ubuntuforums.org:80

Where should be replaced by the name of your laptop.

This is done for whole computer so you dont need to do this from r studio.

Offcourse you need to forward your port to 3036. But you need special privilige on the server. Because on most hosting you can only connect from localhost (for example from php)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值