sarpunk has asked for the wisdom of the Perl Monks concerning the following question:
I'm getting an "Access denied for user" error message when trying to connect to a MySQL database using DBI. I have no problem connecting with mysql -u borp -p $auth from command line, and the user borp has all privileges for borp.* I'm pretty stuck... The relevant bits of code:
Resolved. ><use strict; use warnings; use DBI; my $auth = &read_prompt("Authorize: "); $auth =~ s/\n//; ############## Added this to fix. my $output = &connect("show tables"); exit; sub read_prompt { my $message = $_[0]; print $message; system ("stty -echo"); my $out = <STDIN>; system ("stty echo"); print "\n"; return $out; } sub connect { my $query = $_[0]; my $dbh = DBI->connect('DBI:mysql:borp:localhost:3306' +,'borp',$auth) or die "Unable to connect to db: ".$DBI::errstr."\n"; my $sth = $dbh->prepare($query); my @result = (); $sth->execute(); if($query=~m/^select|^show|^desc/i){ @result = $sth->fetchrow_array(); } $sth->finish(); $dbh->disconnect; return \@result; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: MySQL with DBI: Access denied for user
by vinoth.ree (Monsignor) on Mar 04, 2013 at 05:00 UTC | |
by sarpunk (Initiate) on Mar 22, 2013 at 02:16 UTC | |
|
Re: MySQL with DBI: Access denied for user
by Anonymous Monk on Mar 04, 2013 at 04:48 UTC |