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.


In reply to Re^5: How do you use Net::OpenSSH to query mysql database via ssh tunnel by Corion
in thread How do you use Net::OpenSSH to query mysql database via ssh tunnel by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.