in reply to Using Net::SSH2 with DBI

Depending on how your network setup actually is, most likely the sanest approach is to create an SSH tunnel and then connect DBI to the local end of that tunnel.

From a quick look through Net::SSH2, it doesn't seem that it readily supports setting up a tunnel. I think you can use the ->tcpip method to forward packets yourself, but that feels like far too much programming.

Personally, I would simply launch ssh -L local:remote:remoteport or however one sets up an ssh tunnel from the command line, and then direct DBI / DBD::mysql to connect to the local port. Most likely this is what HeidiSQL does as well.

Replies are listed 'Best First'.
Re^2: Using Net::SSH2 with DBI
by stevieb (Canon) on Jan 19, 2016 at 19:25 UTC

    After a quick search, this is almost exactly what you stated in this post in this thread nearly three years ago :)

    From what I can tell, not much has changed.

      I would really like there to be a nicer/more integrated solution, but I think with libssh2, you have to do the packet forwarding yourself, which means that you will need at least threads or some very clever asynchronous framework to run both the forwarding and DBI queries. And spawning an external process is much simpler than that, at least if you have the ssh executable available.

Re^2: Using Net::SSH2 with DBI
by diyaz (Beadle) on Jan 20, 2016 at 19:15 UTC
    thanks i decided to install cygwin and open ssh in shell with perl. hopefully that will work. UPDATE: I apparently do not know how to use "open" to open an SSH connection. I tried:
    open(SSH, "ssh user\@host.com");
    as a simple example, and I have tested that syntax will work in Cygwin except it will prompt for password. I don't think I understood what you had previously.

      I would either set up a passwordless keypair or use ssh-agent to store the password credentials.