Problem conecting to Database using perl....Guys do help me out .....
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Problem conecting to Database using perl....Guys do help me out .....
Hi
I have written a script to connect to database using mysql and get the table. I am pasting the script here. But its giving me an error that Access Denied, though if I log in to mysql using same user , i m able to log in. But not using script.
The script is
#!/usr/bin/perl
use DBI;
$dbh = DBI->connect('dbi:mysql:mysql','root','redhat') or die "Connection Error: $DBI::errstr \n";
$sql="select * from SUNNY";
$sth=$dbh->prepare($sql);
$sth->execute or die " SQL Error: $DBI::errstr\n";
while (@row = $sth->fetchrow_array){
print "@row\n";
}
its giving an error that ...
DBI connect('mysql','root',...) failed: Access denied for user 'root'@'localhost' (using password: YES) at ./test line 5
Connection Error: Access denied for user 'root'@'localhost' (using password: YES)
if I log in directly , I m able to log in and even have full grants.
mysql> show GRANTS;
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)
Hi
I have written a script to connect to database using mysql and get the table. I am pasting the script here. But its giving me an error that Access Denied, though if I log in to mysql using same user , i m able to log in. But not using script.
The script is
Code:
#!/usr/bin/perl
use DBI;
$dbh = DBI->connect('dbi:mysql:mysql','root','redhat') or die "Connection Error: $DBI::errstr \n";
$sql="select * from SUNNY";
$sth=$dbh->prepare($sql);
$sth->execute or die " SQL Error: $DBI::errstr\n";
while (@row = $sth->fetchrow_array){
print "@row\n";
}
its giving an error that ...
DBI connect('mysql','root',...) failed: Access denied for user 'root'@'localhost' (using password: YES) at ./test line 5
Connection Error: Access denied for user 'root'@'localhost' (using password: YES)
if I log in directly , I m able to log in and even have full grants.
Please use CODE tags in the future..makes things easier to read. And if that's the EXACT code you're using above, the problem is pretty clear. I'd suggest you reference the docs on the Perl:BI module. You're not calling it correctly...try this:
Code:
$dbh = DBI->connect('DBI:mysql:DATABASE NAME GOES HERE', USER, PASSWORD,{ RaiseError => 1}) or die "Could not connect to database! $DBI::errstr";
You missed the DBI being upper-case (things are case sensitive), and specified your database name as 'mysql', which is reserved.
I corrected the script as below ..but still same error.
$dbh = DBI->connect('DBI:mysql:MANMEET','root','redhat') or die "Connection Error: $DBI::errstr \n";
Ok...does the root user actually HAVE a password set, because by default the MySQL root user doesn't. And where is the RaisError string in your corrected version? Have you tried a different MySQL user ID?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.