tags:

views:

87

answers:

2

Hi,

I am trying to connect to a mysql server which is running at port 3307. How do I connect to the server? I do not see any other way to specify port. I am using like this:

#!/usr/bin/perl
use Mysql;

$host = "localhost";
$database = "abc";
$tablename = "def";
$user = "uuu";
$pw = "ppp";


$connect = Mysql->connect($host, $database, $user, $pw) or die "Cannot connect to MySQL server\n";

I want to use MySQL package and not DBI.

Thank you.

+1  A: 

Try specifying host like localhost:3307

Byron Whitlock
+5  A: 

You are mistaken. You want to use DBI and not Mysql. The Mysql module became obsolete 12 years ago, when it was replaced with a compatibility module that's just a wrapper around DBI. Even the compatibility module has been removed from the current distribution; you have to install an old DBD::mysql just to get it (it last shipped in DBD-mysql 3.0008, released back in 2006).

#!/usr/bin/perl

use strict;
use DBI;

my $host = "localhost";
my $database = "abc";
my $port = 3307;
my $tablename = "def";
my $user = "uuu";
my $pw = "ppp";

my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host;port=$port",
                       $user, $pw)
  or die "Cannot connect to MySQL server\n";
cjm