zelf has asked for the wisdom of the Perl Monks concerning the following question:

First time post and first use of perl. So please go easy on me if there is a simple fix to my problem.

Using the following script:

use lib '/usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi/DBD' +; use DBI; use mysql; $hostname="localhost"; $db="database"; $port="3306"; $dbuser="username"; $dbpassword="password"; $table="table"; $DBI_DSN="dbi:mysql:database=$db;host=$hostname;port=$port"; $dbhandle = DBI->connect($DBI_DSN,$dbuser,$dbpassword,{ RaiseError => +1, AutoCommit => 0});
I get the following error:
DBI connect ('database=database;host=localhost;port=3306','username',. +..) failed: Access denied for user: 'username@localhost.localdomain' +(Using password: YES)...
I can connect from mysql command line with the username and password no problem. I can also connect via php from my website, but just not from perl.

I'm at a loss and have searched everywhere I know of for a clue to this, but can't find any discussion.

Any help would be much appreciated.

Thanks.

2004-12-02 Janitored by Arunbear - added code tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re: MySQL Access is Denied
by neniro (Priest) on Dec 02, 2004 at 23:02 UTC
    I had some trouble installing a new version of mysql and phpmyadmin these days. Solution was to set the password using the OLD_PASSWORD()-function as described here. It's also necessary to change the my.ini file to support those old passwords.
Re: MySQL Access is Denied
by StrebenMönch (Beadle) on Dec 02, 2004 at 21:25 UTC
    MySQL Documentation has some information about this error and how to fix it, not sure if it will help or not...
    S t r e b e n M ö n c h
      Thanks for the advice. I had already gone through it. I have narrowed it down to the password. If I kill the password in mysql and connect from my pl script without a password I can connect no problem. How do I tell perl to use the same password encryption as mysql. I assume encryption is the problem here.
        How are you setting your password in MySQL?
        You have probably allready seen this, but...

        If you change a password by using SET PASSWORD, INSERT, or UPDATE, you must encrypt the password using the PASSWORD() function. If you do not use PASSWORD() for these statements, the password will not work. For example, the following statement sets a password, but fails to encrypt it, so the user will not be able to connect afterward:

        mysql> SET PASSWORD FOR 'abe'@'host_name' = 'eagle';
        Instead, set the password like this:
        mysql> SET PASSWORD FOR 'abe'@'host_name' = PASSWORD('eagle');

        The PASSWORD() function is unnecessary when you specify a password using the GRANT statement or the mysqladmin password command, both of which automatically use PASSWORD() to encrypt the password.

        S t r e b e n M ö n c h
        Even i had exactly the same issue with same code like you have. But i changed double codes to single code in the password field value and it worked!
Re: MySQL Access is Denied
by dragonchild (Archbishop) on Dec 02, 2004 at 19:37 UTC
    Are you using MySQL 4.1 or higher? If you are, you may have to recompile your DBD::mysql to use the new password libraries.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      meant to put in system info: using mysql-4.0.22 on fedora 2, with latest perl installed by cpan.
Re: MySQL Access is Denied
by trammell (Priest) on Dec 02, 2004 at 20:09 UTC
    I notice that the user connecting is username@localhost.localdomain. Does that userid have access, or just username@localhost?
      I tried changing the $host to 127.0.0.1 and that shows me connecting as localhost.localdomain. If I change $host to localhost it tries to connect as just localhost. Either way I get the same Access denied. I have tried adding a user account in linux for my username as well, but that doesn't help either. I can log into the username in linux and connect mysql using the username and password in my pl script. Do you think this is a permissions problem in linux?
        No, I was thinking maybe a MySQL permissions problem.