How do I connect to a RDS MySQL instance from RStudio via a bastion host?

Viewed 504

I would like to use RStudio for analysis of data on a MySQL instance. This is a AWS RDS MySql instance that is only accessible via a jump box / bastion host. I have the credentials necessary to connect to the jump box, and from the jump box to the RDS instance. What do I need to do be able to query this DB directly from within the RStudio console?

I can connect (using the Terminal tab in RStudio)to the jump box using: ssh -p 22xx user@ip.add.re.ss

Then I can connect to RDS mysql using: mysql -u username -p database -h hostname.us-east-1.rds.amazonaws.com

I can connect and do manual mysql commands from within RStudio terminal, but I don't seem to be able to do anything with the DB from the RStudio console.

1 Answers

Sorry for opening a 2yo thread, but for everyone dealing with this issue as I am - I found this thread and it looks like it works (connecting with MySQL via ssh from R Studio).

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)

Source: https://www.py4u.net/discuss/881859

Related