?
Solved

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

Posted on 2007-03-20
5
Medium Priority
?
1,890 Views
Last Modified: 2012-08-14
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/MySQL.pm 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;
      $mysql->close;
}

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:

#!/usr/bin/perl

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

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

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

What could be the problem???
0
Comment
Question by:bemara57
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 28

Expert Comment

by:FishMonger
ID: 18762270
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?
0
 
LVL 17

Expert Comment

by:mjcoyne
ID: 18762825
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 "myserver.mydomain.org" 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)?
0
 

Author Comment

by:bemara57
ID: 18765285
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 test.pl 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.
0
 
LVL 17

Expert Comment

by:mjcoyne
ID: 18768712
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 "$!";
0
 
LVL 1

Accepted Solution

by:
the__tyrant earned 2000 total points
ID: 18781776
There seems to be some kind or problem with the Net::MySQL protocol:
http://forums.mysql.com/read.php?51,96826,96826

This has been corrected by adding code to the Net::MySQL package which can be downloaded from here: http://rt.cpan.org/Public/Bug/Display.html?id=21462
(top thread, click the "Download MySQL.pm" button in thread)
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question