LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-18-2008, 02:26 AM   #1
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
Authentication failing in Perl DBI script


Hi all,
I'm trying to access a MySQL database within a Perl program, which goes like this:



#! /usr/bin/perl

use DBI ;
use strict ;


use CGI ;
my ($cgi) = new CGI ;



my ($dsn)="DBI:mysql:dr:localhost";
my ($user_name) = "fubar" ;
my ($password) = "secret" ;
my ($dbh,$sth) ;
my (@ary) ;


$dbh = DBI->connect ($dsn, $user_name, $password, { RaiseError => 1 });


, and on MySQL, at the command prompt, I've typed this:

grant all on *.* to fubar identified by "secret" ;


However when I run the program, I get this error:
DBI connect('dr:localhost','fubar',...) failed: Access denied for user 'fubar'@'localhost' (using password: YES) at ./test.cgi line 19


Can someone help me out?


Thanks.
 
Old 11-18-2008, 02:51 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
When you grant access, you need to specify a host: http://dev.mysql.com/doc/refman/5.0/en/grant.html
 
Old 11-18-2008, 02:54 AM   #3
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Original Poster
Rep: Reputation: 62
But if I don't specify one, my MySQL book tells me that it's supposed to take "localhost" by default - and the error message seems to corroborate this.......?

Last edited by resetreset; 11-18-2008 at 02:56 AM.
 
Old 11-18-2008, 07:22 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
My std sub looks like this
Code:
#! /usr/bin/perl -w

use DBI ;
use strict ;

sub db_connect
{
    my (
        $db,    # database to connect to
        $dsn,   # data source name
        );

    # Create data source string and connect ...
    $dsn = "DBI:mysql:".
           "database=".$cfg::params{'DB_NAME'}.";".
           "host=".$cfg::params{'DB_HOST'}.";".
           "port=".$cfg::params{'DB_PORT'};
    $cfg::dbh = DBI->connect( $dsn, $cfg::params{'DB_USER'},
                                $cfg::params{'DB_PASSWD'},
                                {RaiseError => 0, AutoCommit => 1} );

    if( $DBI::errstr)
    {
        exit_with_error($DBI::errstr);
    }
}
note that the delimiters are colon ( : ) and semi-colon ( ; ) in different places. You've only used colons.
you may want to RaiseError => 1. I always handle all the erroys 'manually'/programmatically inside the code, as my progs run without user interaction, hence my exit_with_error() sub.
I've always used host specifier, but as you say, re-reading the link, it appears its not strictly necessary, although it is for me on production systems.
You 'might' need to flush privileges : http://dev.mysql.com/doc/refman/5.0/en/flush.html
Probably also a good idea to check the grant: http://dev.mysql.com/doc/refman/5.0/en/show-grants.html
 
Old 11-19-2008, 10:01 AM   #5
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Original Poster
Rep: Reputation: 62
Hey I put in the "localhost" and it works! Thanks a lot!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error using DBI with Perl bostonantifan Ubuntu 0 11-11-2007 02:47 PM
squid authentication using perl script Pratik H Pandya Linux - Networking 1 10-28-2006 07:40 AM
client authentication passed onto perl script paul_mat Programming 1 02-12-2006 11:47 PM
DBI data_sources authentication?!? PenguinPwrdBox Programming 0 09-15-2005 12:19 PM
Need Help With My Perl/cgi Authentication Script dutch357 Programming 0 04-11-2003 10:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration