User Tools

Site Tools


Perl, SSH and Mysql

Linux example

First connect a port from another system. System A is running Mysql, system B is a client wanting to access the database.

export A=
export B=

pi@B:~/pl$ ssh -f sql@A -N -L 3336:
# It's confusing, but this connects port 3306 on A to port 3336 on B
pi@B:~/pl$ cat

use strict;
use warnings;
use DBI qw(:sql_types);

my $host = "localhost";
my $database = "example";
my $port = 3336;
my $user = "user1";
my $pw = "123password";

$dbh = DBI->connect("DBI:mysql:database=$database;host=$host;port=$port", $user, $pw)
  || die "Connect failed: $DBI::errstr\n";
  print "OK\n";
perlsql.txt · Last modified: 2023/02/20 13:02 by admin