MySQL Forums
Forum List  »  Perl

Access denied for user 'csci401'@'local host
Posted by: Salman Mahmood
Date: February 19, 2007 07:13PM

I wrote a simple program in Perl, i didn't use or set any password. i only use standard settings in "MySQL server 5.0" and also whenever i clicked on a "MySQL Command Line Client" it also required password but i didn't set any password for these .

##################################################################################
# Description: This sample perl DBI program demonstrates The following:
# - Connecting to a MySQL DB through the DBI & DBD drivers
# - executing a SQL statment(2 different techniques)
# - processing the result set
# - printing the output
# - reusing statment handles
##################################################################################
use strict;
#use warnings;
use DBI; # Load the DBI perl module

my $dbh = DBI ->connect('DBI:mysql:spj','csci401','class') or die "Cannot connect to database: " . DBI->errstr;
my $sth = $dbh->prepare('SELECT jnum,jnum,city FROM project') or die "cannot prepare statment : " . $dbh->errstr;
my $rc=$sth->execute() or die "cannot executestatment:" . $sth->errstr;
my ($jnum, $jname,$city);

print "\n";
print "Proj_Num\tProj_Name\tCity\n";
print "======\t======\t====\n";

my @row;
while (@row=$sth->fetchrow_array()){
$jnum= $row[0];
$jname=$row[1];
$city=$row[2];
print"$jnum\t\t$jname\t\t$city\n";
}
if($sth->rows==0){
print "No rows found.\n\n";
}

my($inp,$stmt,$cnt);
print"\nenter city";
$inp=<>;
champ $inp;

$stmt="SELECT count(city)
FROM project
WHERE city='" . $inp."'";
($cnt) = $dbh->selectrow_array($stmt);
print "City: $inp\t# projects: $cnt\n";

$rc=$sth->finish;
$rc=$dbh->disconnect or warn"Cannot disconnect from database:". DBI->errstr;
exit $rc;


OutPUT:

DBI connect('spj','csci401',...) failed: Access denied for user 'csci401'@'local
host' (using password: YES) at C:\BegPerl\Prog10.pl line 19
Cannot connect to database: Access denied for user 'csci401'@'localhost' (using
password: YES) at C:\BegPerl\Prog10.pl line 19.

Options: ReplyQuote


Subject
Written By
Posted
Access denied for user 'csci401'@'local host
February 19, 2007 07:13PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.