How to connect to MySQL using ssh tunnel with perl
-
11-10-2019 - |
Question
I am using Amazon EC2 instance of MySQL and need to modify my perl scripts to connect to the database using ssh tunnel (instead of the plain old hostname:port). Any help is appreciated
Thanks
Solution
well after establishing SSH tunnel connection differs only with hostname and it's 127.0.0.1 (localhost) in that moment
OTHER TIPS
Open a tunnel:
ssh -fNL 3306:localhost:3306 myname@myhost
Then connect to localhost:3306
MySQL attempts to map localhost[:port] connections to use a local (UNIX) socket; you should use 127.0.0.1 for a tcp/ip socket.
I don't know about ssh but you can encrypt connections between your application and your DB Instance using SSL, would that be sufficent for you?
One note in regard to answer by chris - on some setups "localhost" and "127.0.0.1" make a difference. In my case, localhost didn't work, while 127.0.0.1 did work flawlessly.