pt-heartbeat監測mysql主從同步延遲:mysql
安裝percona toolkit(pt-heartbeat爲該軟件的子命令):sql
http://repo.percona.com/release/6/RPMS/x86_64/percona-toolkit-3.0.13-1.el6.x86_64.rpmide
在主庫上建立heartbeat表:server
use ming;
create table heartbeat(ts varchar(26) not NULL, server_id int unsigned NOT NULL PRIMARY KEY, file varchar(255) DEFAULT NULL, position bigint unsigned DEFAULT NULL, relay_master_log_file varchar(255) DEFAULT NULL, exec_master_log_pos bigint unsigned DEFAULT NULL);
exitget
更新主mysql的heartbeat表,每1秒鐘更新1次(這裏的root爲mysql的root):同步
在主mysql上運行監測同步延遲(需先在從mysql上受權):it
將延遲結果記錄到文件裏:io