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

Hello I have installed NET::MySQL module and I am trying to connect to MySQL database and send a query. I am able to manually connect to MySQL DB with Details below however when I try to connect using the script below I get the following error; Access denied for user: '@sb-desktop.local.server.com' (Using password: NO) at MySQL_queryDB.pl line 5 It seems as though the password is not being sent... any ideas how to resolve this. thanks for your help in advance. Mr P
## Perl script to log into Database and quesry Tables use Net::MySQL; my $mysql = Net::MySQL->new( hostname => 'testscript', database => 'test', user => 'tester', password => 'tester' ); # SELECT example $mysql->query(q{SELECT * FROM product_releases}); my $record_set = $mysql->create_record_iterator; while (my $record = $record_set->each) { printf "First column: %s Next column: %s\n", $record->[0], $record->[1]; } $mysql->close;
  • Comment on NET:MySQL database connection error -- (Using password: NO) at MySQL_queryDB.pl
  • Download Code

Replies are listed 'Best First'.
Re: NET:MySQL database connection error -- (Using password: NO) at MySQL_queryDB.pl
by marto (Cardinal) on Sep 24, 2009 at 11:20 UTC

    Which version of MySQL are you running? The last release of Net::MySQL was over three years ago, I've never used it (though I've used DBD::MySQL). Try adding debugging in your constructor:

    my $mysql = Net::MySQL->new( hostname => 'testscript', database => 'test', user => 'tester', password => 'tester', debug => 1 );

    Super search shows that people are having problem with this module, looking at some of those issues may be worth while.

    Update: Also look to see if any of the reported bugs for Net::MySQL are relevant.

    Martin

      I am using version Net-MySQL-0.09 see response when I turned debug on;
      pohara@pohara-desktop:~/automation$ perl MySQL_queryDB.pl Use INET Socket: testscript 3306/tcp Net::MySQL::_get_server_information(): 30 00 00 00 0A 34 2E 30 2E 32 36 2D 73 74 61 6E 0....4.0.26-stan 64 61 72 64 00 83 20 00 00 57 39 58 2D 75 2A 6B dard.....W9X-u*k 60 00 2C 20 08 02 00 00 00 00 00 00 00 00 00 00 ..,............. 00 00 00 00 .... Protocol Version: 10 Server Version: 4.0.26-standard Salt: W9X-u*k` Net::MySQL::_send_login_message(): 41 00 00 01 0D A6 03 00 00 00 00 01 21 00 00 00 A............... 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 74 65 73 74 65 72 00 14 93 96 51 55 ....tester....QU 6C AC FB C7 30 FC 89 04 3B A8 77 74 60 17 A3 4F l...0...;.wt...O 74 65 73 74 00 test. Net::MySQL::_request_authentication(): 4E 00 00 02 FF 15 04 41 63 63 65 73 73 20 64 65 N......Access.de 6E 69 65 64 20 66 6F 72 20 75 73 65 72 3A 20 27 nied.for.user..' 40 73 62 2D 64 65 73 6B 74 6F 70 2E 6C 6F 63 61 .sb-desktop.loca 6C 2E 63 6F 72 76 69 6C 2E 63 6F 6D 27 20 28 55 l.corvil.com'.(U 73 69 6E 67 20 70 61 73 73 77 6F 72 64 3A 20 4E sing.password..N 4F 29 O) Access denied for user: '@sb-desktop.local.server.com' (Using password +: NO) at MySQL_queryDB.pl line 5 pohara@pohara-desktop:~/automation$

        Hmm, I don't have time to look any further at Net::MySQL at the momemnt, have you considered using DBD::MySQL as mentioned in the MySQL documentation?

        Martin

Re: NET:MySQL database connection error -- (Using password: NO) at MySQL_queryDB.pl
by proceng (Scribe) on Sep 24, 2009 at 20:17 UTC
    Just off the top of my head, I do not see a connection made to the database. This would seem to be borne out by Access denied for user: '@sb-desktop.local.server.com' (Using password: NO) at MySQL_queryDB.pl line 5, where the user name should come before the "@sb-desktop.local.server.com" (ie should be "testuser@sb-desktop.local.server.com"
    Check the NET::MySQL docs (if you want to stay with this package) to make sure if a connect command is needed. I suspect that that is going to be the case.