Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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. ><

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

    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!
Re: MySQL with DBI: Access denied for user
by Anonymous Monk on Mar 04, 2013 at 04:48 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1021577]
Approved by vinoth.ree
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2017-06-26 01:17 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (572 votes). Check out past polls.