#!/usr/bin/perl use DBI; use warnings; use strict; use Term::ReadKey; my $dsnL = "dbi:mysql:database=test;host=127.0.0.1;port=3306"; my $dbhLocal = DBI->connect($dsnL, 'root',''); $dbhLocal->{mysql_auto_reconnect} = 1; my $exit; ReadMode 4; for ( ; ; ) { if ($dbhLocal->ping()) { print "OK\n"; } else { print "FAILED\n"; } defined( $exit = ReadKey(-1) ) && $exit ne 'Q' ? last : sleep 5; } ReadMode 0; exit 0;