Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I'm trying to figure out how run mysql queries on a remote server over SSH using a tunnel. Here's what I got so far, but I have no idea if I'm on the right path so I could be way out to lunch:

use Net::OpenSSH; use DBI; use Modern::Perl; use Data::Dumper; my $ssh = Net::OpenSSH->new('me@10.0.1.17'); my ($socket, $pid) = $ssh->open_tunnel('10.0.1.17', '3306'); print Dumper $socket; print Dumper $pid; my $dsn = "DBI:mysql:database=calendar;mysql_socket=$socket"; my $dbh = DBI->connect($dsn, 'user', 'pass');

This throws an error:

$VAR1 = \*{'Net::OpenSSH::$win'}; $VAR1 = 12877; DBI connect('database=calendar;mysql_socket=GLOB(0x20f38e0)','user',.. +.) failed: Can't connect to local MySQL server through socket 'GLOB(0 +x20f38e0)' (2) at t/XMLRPC.t line 27. at /usr/lib/x86_64-linux-gnu/perl5/5.20/DBI.pm line 685.

I'm not sure how to dereference that glob in a way that would be useful to DBI. Thanks.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks


In reply to 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2024-04-23 16:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found