MySQL dropping connections is a frequent problem, so much so that the DBD::mysql driver has that feature built-in to reconnect. It looks like you fund that feature and have it enabled and working in the example.

You gave an example of it working, so that doesn't give us much to figure out the one that doesn't work. One thing that prevents the auto-reconnect is if you left a transaction open. DBD::mysql can only retry one query after auto-reconnect, so it can't get a new transaction back to the state it was in before the disconnect, so it doesn't try.

For web apps, if DBD::mysql isn't reconnecting automatically, you could call eval { $conn->ping } at the start of the request, and you could even call ->connect again if that fails.

As it happens, just about 3 weeks ago I was trying to *disable* the mysql auto-reconnect because I wanted to know when there was a new connection ID, to have the ability to log and kill long-running queries associated with a user account. Setting {mysql_auto_reconnect}= 0 had no effect. I didn't get around to reporting that bug yet. Maybe that bug is related to the problem you're having on Debian.


In reply to Re: DBI keep alive by NERDVANA
in thread DBI keep alive by Anonymous Monk

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.