Connect to MySQL & Postgres over SSH Tunnel


#1

Hi All,
Is it currently possible to have a MySQL or Postgres data source that is connected to via an SSH tunnel?
Cheers,
Josh


Add ssh gateway setting to MySQL(Amazon RDS)
オンプレのredash環境からAmazon RDSへの接続について
#2

Yes, use ssh to create the tunnel first then connect redash to the tunneled port.

ssh -N -Llocalport:remotedbhost:remoteport user@sshhost

Eg
ssh -N -L3307:localhost:3306 user@myserver.com

You can specify multiple -L parameters to map MySQL and Postgres

Then simply connect to port 3307.

I have this running as an upstart job in on my redash machine to keep the tunnel open 24/7.


#3

I would also look into autossh as a way to reliably keep the tunnel open.


#4

Thanks both, I wasn’t sure if I was missing an option in the GUI that would have redash open the tunnel, use it for a query & close it afterwards, but leaving it open is fine :slight_smile:

Thanks for pointing out autossh as well, I’d never seen it before & it looks awesome!


#5

Is there a way to have the SaaS version talk to our postgres database? I presume the described mechanism would only work if we were running our own redash.

Thanks!


#6

There is no UI to control it, but we can setup the tunnel for you if needed.


#7

Is there any good way of doing this with the docker deployment. Especially the workers.


#8

I have the same issue but don’t have ssh access to my database server. However, I can connect to mysql from another server in the same network. how should I proceed? I did this:

autossh -N -L3307:ssssadasd.rackspaceclouddb.com:3306 root@IP -C

I get this error:

Connection Test Failed:
Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)


#9

Did you find a workaround @hadifarnoud or @Slind ?