Can't run any Perl scripts with Net::MySQL, same error all the time. Pls help!

I just installed Net::MySQL for Perl and was successful (no errors). But when I run a simple test script, it always fails with the same error:

send: Cannot determine peer address at /usr/local/lib/perl5/site_perl/5.8.8/Net/ line 100

This is line 100 ($mysql->send($quit_message, 0);):
sub close
      my $self = shift;
      my $mysql = $self->{socket};
      return unless $mysql->can('send');

      my $quit_message =
            chr(length(COMMAND_QUIT)). "\x00\x00\x00". COMMAND_QUIT;
      $mysql->send($quit_message, 0);
      $self->_dump_packet($quit_message) if Net::MySQL->debug;

I've tried many examples of script involving inserts, select, create, etc. They all have the same error. I know I have access to the database since I can do commands from the shell, but not thru Net::MySQL. Here's one example:


use Net::MySQL;
use strict;
my $mysql = Net::MySQL->new(
hostname => '192.168.xx.xx',
database => 'test_db',
user     => 'xxx',
password => 'xxx'

      INSERT INTO test (flag) VALUES (9)
  printf "Affected row: %d\n", $mysql->get_affected_rows_length;

This is what it returns:
# perl
Affected row: 0
send: Cannot determine peer address at /usr/local/lib/perl5/site_perl/5.8.8/Net/ line 100

What could be the problem???
Who is Participating?
the__tyrantConnect With a Mentor Commented:
There seems to be some kind or problem with the Net::MySQL protocol:,96826,96826

This has been corrected by adding code to the Net::MySQL package which can be downloaded from here:
(top thread, click the "Download" button in thread)
I have not used that module; I always use the DBI and DBD::mysql modules, but have you tried enabling debug when creating the object?  What output do you get when debug is enabled?
I haven't used this module either, but a few things to check:

Are you sure the "hostname" parameter in the object creation accepts an IP address?  Could it be looking for "" or some other form?

Is the MySQL installation you're trying to reach configured to allow remote connections?

Assuming you have MySQL installed locally, can you connect from your command line (e.g. mysql -h hostname -P port -u username -ppassword)?
bemara57Author Commented:
FishMonger: I tried putting the hostname instead (and made sure it's added to /etc/hosts) but same problem persists. I also put the debugging and here's the error I got:
#08S01Bad handshake at line 15.

mjcoyne: I am able to connect to the remote MySQL database from the shell command (mysql -h hostname -P port -u username -ppassword) so I have access, just not thru Perl.

Anything else I'm missing? It's gotta be the bad handshake, but what does that mean and how do I fix that? I just don't get why it's fine at the shell, but not within the Perl script.
What is at line 100 in your actual script?  Are we sure this is failing to connect?  Where is "send:" coming from?  What happens if you do:

my $mysql = Net::MySQL->new(
hostname => '192.168.xx.xx',
database => 'test_db',
user     => 'xxx',
password => 'xxx'
) or die "$!";
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.