Jump to content

How Do I Connect To The Mysql Server Via A Perl Script?


Recommended Posts

I've tried this:

 

$dbh = DBI->connect("DBI:mysql:kymercer_obits:[dbserver]", [user], undef, undef);

 

I've put various things in for dbserver and user, but keep getting messages like this:

 

Access denied for user 'kymercer'@'localhost' (using password: NO)

 

 

In the above example, I'd put 'kymercer' in for user, and 'localhost' as the server.

 

What should I put here to get it to connect? Any help appreciated.

Link to comment
Share on other sites

Try this:

 

#!/usr/bin/perl

use strict;
use DBI;

my $host = "localhost";
my $database = "database1";
my $port = 3307;
my $tablename = "table1";
my $user = "userName";
my $pw = "pass";

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

 

source: http://stackoverflow.com/questions/2248665/perl-script-to-connect-to-mysql-server-port-3307

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...