Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PERL DBI remote mysql db connection 1

Status
Not open for further replies.

chrisw669

Technical User
Feb 19, 2002
43
US
I'm used to connecting to a local mysql dbase using ::
my $database = "mydb";
my $dbh = DBI->connect("DBI:mysql:database=$database",
'usr', 'pass') || die "couldn't open";

My question is how do i go about connecting to a mysql dbase on a different server?
 
Read the perldocs for the DBD::mysql module by doing

perldoc DBD::mysql

at a command prompt - I'm certain that those perldocs explain how to connect to a remote database.

In fact, I just did 'perldoc DBD::mysql' and here's a small section of what I found:

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

$dbh = DBI->connect($dsn, $user, $password);

Looks to me like you just specify "host=$hostname" to connect to a mysql database on a remote server. Of course the permissions for $user must be set up properly in mysql on that remote database.

HTH. Hardy Merrill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top