use strict; use DBI; my $mysql = DBI->connect('DBI:mysql:database=mydb;host=myhost;port=3306', '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 here that may take a while. } #### 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.