Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl: the Markov chain saw
 
PerlMonks  

MySQL with DBI: Access denied for user

by sarpunk (Initiate)
on Mar 04, 2013 at 04:39 UTC ( #1021577=perlquestion: print w/ replies, xml ) Need Help??
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:

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; }
Resolved. ><

Comment on MySQL with DBI: Access denied for user
Select or Download Code
Re: MySQL with DBI: Access denied for user
by Anonymous Monk on Mar 04, 2013 at 04:48 UTC
Re: MySQL with DBI: Access denied for user
by vinoth.ree (Vicar) on Mar 04, 2013 at 05:00 UTC

    1.When reading user input from the standard input stream (STDIN) for instance, you get a newline character with each line of data. chomp() is really useful in this case because you do not need to write a regular expression and you do not need to worry about it removing needed characters.

    2.The chomp() function will remove (usually) any newline character from the end of a string. The reason we say usually is that it actually removes any character that matches the current value of $/ (the input record separator), and $/ defaults to a newline

      That's good to know about the second point! Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1021577]
Approved by vinoth.ree
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-04-19 00:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (474 votes), past polls