How to connect to MySQL using ssh tunnel with perl
I am using Amazon EC2 instance of MySQL and need to modify my perl scripts 开发者_JAVA技巧to connect to the database using ssh tunnel (instead of the plain old hostname:port). Any help is appreciated
Thanks
Open a tunnel:
ssh -fNL 3306:localhost:3306 myname@myhost
Then connect to localhost:3306
well after establishing SSH tunnel connection differs only with hostname and it's 127.0.0.1 (localhost) in that moment
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.
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.
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?
精彩评论