-
#!/usr/bin/perl
-
-
#author: zhengsenlin
-
#date: 2013-03-12
-
#desc: perl conn mysql
-
-
use 5.012;
-
use strict;
-
use warnings;
-
use autodie;
-
-
#load module
-
use DBI;
-
use Time::Piece;
-
-
#mysql config
-
my $mhost = "localhost";
-
my $muser = "zheng";
-
my $mpass = "123456";
-
my $mport = 3306;
-
my $mdatabase = "ffff";
-
-
#connect mysql
-
my $dbh = DBI->connect("DBI:mysql:database=$mdatabase;host=$mhost;port=$mport", $muser, $mpass, {'RaiseError' => 1});
-
my $sth = $dbh->prepare('select * from prowl');
-
$sth->execute();
-
while (my $ref = $sth->fetchrow_hashref()) {
-
my $t = localtime($ref->{'monit_time'});
-
my $real_time = $t->ymd . " " . $t->hms;
-
say "$ref->{'server'}\t$ref->{'type'}\t$ref->{'value'}\t$real_time";
-
}
-
$sth->finish();
-
-
#disconnect mysql
- $dbh->disconnect();