Mysql->Connect and Ports

T

Todd Hlavacek

Hello all,

A quick question to the community. I'm trying to figure out how to
use the Mysql->connect with multiple databases. Somewhere in Google,
some guy said "RTFM perldoc DBD/mysql". I did and that documentation
does not have info on accessing multiple mysql databases on different
ports.

I was wondering that since there is no mention of support for multiple
mysql database instances in the Mysql module, I wonder if we fall back
to DBI->connect... with the port in the arguments passed to the
connect parameter?

Just wondering...
Thanks,
Todd
 
Z

Zebee Johnstone

In comp.lang.perl.misc on 18 Aug 2004 15:03:29 -0700
Todd Hlavacek said:
I was wondering that since there is no mention of support for multiple
mysql database instances in the Mysql module, I wonder if we fall back
to DBI->connect... with the port in the arguments passed to the
connect parameter?


my $dbh=DBI->connect("DBI:mysql:database=$database;host=$Host;port=$port",$username,$password)|| die "couldn't connect to master $Host, $!\n";


You may find it works better if you use a socket rather than a port if
the mysql instances are on the same machine. I've found it better
that way, eg:

my $dbh=DBI->connect("DBI:mysql:$database;mysql_socket=$socketname",$user,$password)


Zebee
 
M

Matthew Braid

Todd said:
Hello all,

A quick question to the community. I'm trying to figure out how to
use the Mysql->connect with multiple databases. Somewhere in Google,
some guy said "RTFM perldoc DBD/mysql". I did and that documentation
does not have info on accessing multiple mysql databases on different
ports.

I was wondering that since there is no mention of support for multiple
mysql database instances in the Mysql module, I wonder if we fall back
to DBI->connect... with the port in the arguments passed to the
connect parameter?

Just wondering...
Thanks,
Todd

The person who told you to RTFM was right - these are the first 7 lines of
perldoc DBD::mysql:

NAME
DBD::mysql - MySQL driver for the Perl5 Database Interface (DBI)

SYNOPSIS
use DBI;

$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

What are you missing here?

To spell it out for you:

my $one_db =
DBI->connect("DBI:mysql:database=FirstDB;host=FirstHost;port=3306");
my $two_db =
DBI->connect("DBI:mysql:database=SecondDB;host=SecondHost;port=9999");

Don't forget your usernames and passwords and you're set.
 
T

Todd Hlavacek

Hi Matthew,

Interesting because my version of perldoc does not pull up that info.
Here's the first part of that mysql as shown by perldoc:

NAME
Msql / Mysql - Perl interfaces to the mSQL and mysql databases

SYNOPSIS
use Msql;

$dbh = Msql->connect($host);
$dbh = Msql->connect($host, $database);

or

use Mysql;

$dbh = Mysql->connect(undef, $database, $user, $password);
$dbh = Mysql->connect($host, $database, $user, $password);

or

$dbh = Msql1->connect($host);
$dbh = Msql1->connect($host, $database);

$dbh->selectdb($database);

@arr = $dbh->listdbs;

I'm using activeperl 5.6.1 (no, we can't upgrade...yet). In that
version, there's no mention of ports.

Thanks to all! I'll try that.
Todd
 
P

Paul Lalli

Hi Matthew,

Interesting because my version of perldoc does not pull up that info.
Here's the first part of that mysql as shown by perldoc:

NAME
Msql / Mysql - Perl interfaces to the mSQL and mysql databases

SYNOPSIS
use Msql;

I'm using activeperl 5.6.1 (no, we can't upgrade...yet). In that
version, there's no mention of ports.

Please don't top post. That means please don't post your reply above what
you're replying to. Thank you.

You're talking about two different modules. You're using the MySql
module, whereas Matthew is telling you to use the DBI and DBD::mysql
modules. Their syntaxes are not the same, as they are different modules.
I believe most people prefer the DBI module because you can very easily
swap out the current DBD::xxx module and replace it with another if/when
you change Database systems. The DBI syntax will remain the same no
matter what database you use.

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top