Hello all.

This seems like it should be a simple problem, and I get the feeling I'm missing something obvious.

Preamble: I'm running ActiveState's Perl v5.8.7 on Windows XP. I have DBD::Mysql v3.0002 and DBI v1.48, installed via PPM. My MySql server is v3.23.54, running on Redhat Linux.

My understanding of mysql_auto_reconnect from the DBD::Mysql docs is that it should automatically reconnect if the server has timed out a connection.

However, in this simple test case:

use strict; use DBI; my $mysql = DBI->connect('DBI:mysql:database=mydb;host=myhost;port=330 +6', 'user', 'password', {RaiseError => 1}); $mysql->{mysql_auto_reconnect} = 1; while (1) { my $query = $mysql->prepare("select count(*) from sometable"); $query->execute(); my ($count) = $query->fetchrow_array; printf "Found %d records.\n", $count; sleep 5*60; # In reality, my program does lots of other things her +e that may take a while. }

It works correctly the first time, but the second time through the loop, I get:

DBD::mysql::st execute failed: Lost connection to MySQL server during +query at foo.pl line 11. DBD::mysql::st execute failed: Lost connection to MySQL server during +query at foo.pl line 11.

(Yes, I did say that twice. (Echo. Echo. :-)))

The server is set to time out after 4 minutes, but why isn't the client auto-reconnecting as necessary?

Am I calling mysql_auto_reconnect in the wrong way? Am I misunderstanding what it's meant to do? Any thoughts will be greatly appreciated.

Many thanks,
Neil.

Edit: g0n - replaced pre tags with code tags


In reply to DBD::MySql - Problem with mysql_auto_reconnect not auto reconnecting. by SmugX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.