mysql_auto_reconnect + "MySQL server has gone away"

mysql_auto_reconnect + "MySQL server has gone away"

am 20.07.2005 16:29:31 von Jim Spath

I have a long running Perl process which has intermittant interaction
with a MySQL database. In order to deal with the inherent connection
problems that occur in a setup like this, I decided to use DBD::mysql's
mysql_auto_reconnect option.

Here's the bit of code that takes advantage of this functionality:

---
my $rc =3D $sth->execute(@$bind);

if (!$rc) {

if ($dbh->errstr &&
$dbh->errstr =3D~ /(?:lost connection|mysql server has gone
away)/i) {

$rc =3D $sth->execute(@$bind);

if (!$rc) {
return;
} else {
return 1;
}

} else {
return;
}

} else {
return 1;
}
---

I have tested this functionality by starting the Perl process, killing
the MySQL process, and forcing the Perl process try to execute a
statement. The 1st execute fails as expected, with a "lost connection"
error. The 2nd execute works as expected, since DBD::mysql
reestablishes the database connection when the 1st execute fails.

The problem I am having is when I leave the process running for a long
period of time with no activity. In this case, BOTH execute commands
fail with a "MySQL server has gone away" error. mysql_auto_reconnect
seems to have no effect in this case.

I do not understand why mysql_auto_reconnect doesn't reconnect to the
MySQL database when the "MySQL server has gone away" error occurs, but
does reconnect when the "lost connection" error occurs. The database is
still up and running, it just timed out the connection. All that is
needed is a reconnect, but no reconnect is attempted. Am I missing
something?

- Jim

PS - I am using Perl v5.6.1 built for i386-linux, DBD::mysql 2.9004, DBI
1.38

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=3Dgcdmp-msql-mysql-modules @m.gmane.org