Home > Archive > MySQL Server Forum > August 2005 > Re: DBI with mysqld (SOLVED)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: DBI with mysqld (SOLVED)
Jay Vollmer

2005-08-07, 11:23 am

On Sat, 06 Aug 2005 23:19:55 -0800, Malcolm Dew-Jones wrote:

> Jay Vollmer (jvollmer@visi.com) wrote:
> : On Sat, 06 Aug 2005 21:28:00 -0800, Malcolm Dew-Jones wrote:
>
> : > Jay Vollmer (jvollmer@visi.com) wrote:
> : > : Hi everybody.
> : >
> : > : Can I use DBI to interface Perl with mysqld running locally rather than
> : > : with a 'true' MySQL server?
> : >
> : > : If not DBI, how can I do this?
>
> : > If you have a mysql database installed and the mysql processes running on
> : > your local computer then your local computer is the mysql server.
> : >
> : > In that case you can use DBI (with perl) to access the database. Just use
> : > "localhost" as the server name.


> "it doesn't work." is not a good enough description. Many things could be
> wrong. At a minimum you need to tell us the exact error message and error
> code, and also show us a minimal script that doesn't work.


Here is an example of the code:

#!/usr/bin/perl
use DBI;
$drh = DBI->install_driver( 'mysql' );
$dbh = DBI->connect("DBI:mysql:test:", 'username', 'password');
die "Cannot connect: $D: $DBI::errstr\n" unless $dbh;

$sth = $dbh->prepare("select * from test;");
$sth->execute;
while (($first_name, $field1, $field2, $field3) = $sth->fetchrow)
{
#Do something here;
}

I get the following error:

DBI connect('test:localh
ost','jvollmer',...) failed: Access denied for
user:
'jvollmer@localhost'
(Using password: YES) at ./testsql.pl line 4
Cannot connect: : Access denied for user: 'jvollmer@localhost'
(Using
password: YES)

But I have no trouble accessing the database using the mysql client.

Okay, that's the exaple and the error. I fixed it by removing the
servername, login and password entirely. It works if I do this:

$dbh = DBI->connect("DBI:mysql:test:");

Thanks for your time anyway.

--
JAY VOLLMER
JVOLLMER@VISI.COM
Bill Karwin

2005-08-07, 8:23 pm

Jay Vollmer wrote:
> DBI connect('test:localh
ost','jvollmer',...) failed: Access denied for
> user:
> 'jvollmer@localhost'
(Using password: YES) at ./testsql.pl line 4
> Cannot connect: : Access denied for user: 'jvollmer@localhost'
(Using
> password: YES)
>
> But I have no trouble accessing the database using the mysql client.


I assume when it works with the mysql client, you are not specifying the
username and password. You'd probably get the same error above if you
did this:

C:> mysql -u jvollmer -p test
Password:
(and enter your password when prompted)

> Okay, that's the exaple and the error. I fixed it by removing the
> servername, login and password entirely. It works if I do this:
>
> $dbh = DBI->connect("DBI:mysql:test:");
>
> Thanks for your time anyway.


I'm glad it's working. For what it's worth, we can explain why you got
that error, it might help you in the future.

You had the database on your local system, and the MySQL service
running, but you hadn't granted access to the database for user jvollmer
when he connects using the password you entered.

You can set up a new user account by using the 'mysql' database and
running this statement:

mysql> grant all on test.* to 'jvollmer'@'localhos
t' identified by
'password';
(substitute the password you want in place of 'password', of course)

See http://dev.mysql.com/doc/mysql/en/adding-users.html for further
reading on this topic.

Regards,
Bill K.
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com