Re: ssh tunneling through a mysql dsn

From: Genny Engel <gengel_at_nyob>
Date: Wed, 25 Jun 2008 12:32:13 -0700
To: CODE4LIB_at_LISTSERV.ND.EDU
Have you tried changing the source port to e.g. 3307 so you avoid the
conflict with your localhost MySQL port?
 
 
 
 
Genny Engel
Internet Librarian
Sonoma County Library
gengel_at_sonoma.lib.ca.us
707 545-0831 x581
www.sonomalibrary.org
 


>>> emorgan_at_ND.EDU 06/25/08 05:59AM >>>
Is there anyway to support SSH tunneling through a MySQL DSN?

I would like to open a database connection to remote host through  
Perl's DBI. The remote database is MySQL, but the server hosting the  
database does not allow outside connections. Instead the systems  
administrators suggest first setting up a local SSH tunnel, and then  
making connections to the host. Something this:

   $ ssh -T -L 3306:mysql.example.org:3306 username_at_login.example.org
&
   $ mysql -h mysql.example.org

Alas, this option does not work for two reasons. First, I get prompted 

for my username after the first command and my shell crashes. Second, 

and more importantly, port 3306 is already in use on my local machine. 

The whole thing seems weird anyway.

Maybe I can configure tunneling in the DBD::mysql DSN? I see that  
DBD::mysql supports SSH, but I see no tunneling option:

   use DBI;
   $database = 'foo';
   $user     = 'bar';
   $password = 'baz';
   $host     = 'mysql.example.org';
   $dsn      = "DBI:mysql:database=$database;host=$host;mysql_ssl=1";
   $dbh      = DBI->connect( $dsn, $user, $password );

Am I missing something, or is there some trickery I can use with the  
definition of $host and/or $database?

-- 
Eric Lease Morgan
Head, Digital Access and Information Architecture Department
Hesburgh Libraries, University of Notre Dame

(574) 631-8604
Received on Wed Jun 25 2008 - 14:08:09 EDT