Reputation: 115
I had written a following perl script to connect with the mysql workbench database, but it is giving the error access denied for user 'root'@'localhost' (using password yes)
.
Error after running the code:
C:\Users\1053130\Desktop>perl mysql.pl
DBI connect('database=dvd_collection','root',...) failed: Access denied for user 'root'@'localhost' (using password: YES) at mysql.pl line 9.
Access denied for user 'root'@'localhost' (using password: YES) at mysql.pl line 9.
I have gone through the similar questions also, but according the these I already have username
and password
. I even changed the root password also. But the error is still the same.
code:
#!/usr/bin/perl
use DBI;
use strict;
my $driver = "mysql";
my $database = "dvd_collection";
my $dsn = "DBI:$driver:database=$database";
my $userid = "root";
my $password = "123";
my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;
Upvotes: 1
Views: 2896
Reputation: 1
if the error says "the access is denied" then there are chances the password is wrong and in xampp server the dafault password to sql will be ' ' .hence just try the below line
my $dbh=DBI->connect("DBI:mysql:perldb",'root','') or die;
Upvotes: 0
Reputation: 3292
Shouldnt my $dsn = "DBI:$driver:database=$database";
rather be
my $dsn = "DBI:$driver:database=$database;host=$hostname;port=$port";
?
Missing the host and port?
Edit:
It says Access denied for... @localhost. Is it a local server? If not, you should declare the server-details as shown above.
Edit2:
According your comment you should check your password, as simple as it sounds. You can go for it with mysql -u root -p newPasswordHere
. Choose a new one and retry.
Edit3:
As you already changed your password, try the following change of your connect:
my $dbh = DBI->connect('dbi:mysql:dbname=dvd_collection;host=localhost','root', '123') || die "Could not connect to database: $DBI::errstr";
I've seen some ppl having some issues with the different formats of the connection.
Upvotes: 1