Wei
Wei

Reputation: 458

Perl script using DBI module to access differently installed MySQL

So I am using Perl DBI module to access MySQL database on a server linux machine, which I do not have root access. The admin installed the MySQL and create a database for me. I can write a Perl script to access the database just fine.

Then I installed MySQL in my local space and change environment variable to use the locally installed mysql executables. I can access the database from command line. But after I change the Perl script accordingly and execute it, I got "Access denied" error. And it seems the Perl script still try to use the admin installed mysql to access.

So how can I solve this?

Here's how I connect:

my $conn = DBI->connect("dbi:mysql:dbname:localhost:3366", "root", "root")
    or die DBI::errstr;

Upvotes: 0

Views: 420

Answers (2)

Wei
Wei

Reputation: 458

I found the solution so I'll answer my own question.

What I did is to re-compile and install perl DBD-mysql module and give it the path of the locally installed mysql.

perl Makefile.PL PREFIX=/path/to/perl/local/lib 
             --mysql_config=/path/to/locally_installed_mysql/bin/mysql_config

Reference: http://cpansearch.perl.org/src/RUDY/DBD-mysql-2.9008/INSTALL.html

Upvotes: 1

Gaurav Pant
Gaurav Pant

Reputation: 4199

Use single quotes generally in database connection string, password string and sql query,because these might give you error with double quotes.As double quotes is used for interpolation.

So please try with single quotes.

my $conn = DBI->connect('dbi:mysql:dbname:localhost:3366', 'root', 'root') or die "..."

I am assuming that you have access to mysql with root user with password through command line (manually) as you stated.

Upvotes: 0

Related Questions