Why do you connect your local MySQL client to 127.0.0.1:3306?
What do you think the $socket value is in the return value of ->open_tunnel?
You will need to find the local port number of $socket and pass that as a number to your local MySQL client library.
Maybe it will help you to draw a picture like the following, but on paper, and to add the IP addresses and port numbers:
|---- Nysus Desktop ---| |---- remote MySQL serve
+r ---|
| 192.168.1.1 | | 10.0.1.17:3306
+ |
| 127.0.0.1:xxx ]==========( ssh tunnel ) =======[ 127.0.0.1:3306
+ |
|----------------------| |-----------------------
+-----|
Update: I don't think you can do what you want using Net::OpenSSH in the way you do, because the documentation says:
Unlike when ssh -L options is used to create tunnels, no TCP port is opened on the local machine at any time so this is a perfectly secure operation.
The MySQL client library will want to talk to a local IP socket, so you need the equivalent of -L instead.
Maybe some other function of Net::OpenSSH provides that functionality. |