3

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.

2
  • 3
    Why don't you want to use DBD DBI ? They are the standard on perl... Commented Feb 11, 2010 at 23:56
  • 1
    -1: No, you want to use DBI. Really. Commented Feb 12, 2010 at 11:10

3 Answers 3

8

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";
Sign up to request clarification or add additional context in comments.

Comments

1

Try specifying host like localhost:3307

Comments

0

For me...Following seems to be working ...

#!/usr/bin/perl

use strict;
use DBI;

my $host = "rajeshk-W7";
my $database = "rajesh";
my $port = 3307;
my $tablename = "def";
my $user = "rajesh";
my $pw = "rajesh123";
#my $dbh = DBI->connect("DBI:mysql:rajesh:rajeshk-W7","rajesh","rajesh123") or die "Cannot connect to MySQL server\n";

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

where i dint mentioned port. When i add port, its unable to connect.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.