in reply to Reconnecting to a mysqldb

The DBD::mysql driver supports auto-reconnect. See perldoc DBD::mysql for all the details, as a small taster:
"DBD::mysql has a "reconnect" feature that handles the so-called MySQL "morning bug": If the server has disconnected, most probably due to a timeout, then by default the driver will reconnect and attempt to execute the same SQL statement again. However, this behaviour is disabled when AutoCommit is off: Otherwise the trans‐action state would be completely unpredictable after a reconnect."

So, you could try just ensuring you have {AutoCommit => 1} included as the last argument to DBI::connect.

If AutoCommit isn't correct for your purposes, then you'll have the same problems as described in the docs if you attempt to seamlessly reconnect behind the scenes.

Replies are listed 'Best First'.
Re^2: Reconnecting to a mysqldb
by clinton (Priest) on Nov 07, 2006 at 11:32 UTC
    However, any per connection variables that you have set will have been forgotten in the reconnect, eg

    SET NAMES "utf8";

    After the reconnect, NAMES will be back to the default.

Re^2: Reconnecting to a mysqldb
by jmo (Sexton) on Nov 07, 2006 at 12:42 UTC
    Yes {AutoCommit => 1} helps me if the database is up at the time of the query but lets say it's down at the exact time of the query, then I want to sleep for say 5 sec and try again, a few times since (in my case) time isn't an issue.

    The only way I can think of that would solve that is by doing my own sub class.

    Sorry for not being clear about that.