MySQL Event monitoring log

Source: Internet
Author: User

Set up a monitoring table:

    CREATE TABLE ' t_event_history ' (    ID INT UNSIGNED not  NULL PRIMARY KEY auto_increment,      ' dbname ' VARCHAR (+) N  OT null default ' cat ',        ' eventname ' VARCHAR (+) NOT null default ' Bakupcat ',        ' starttime ' DATETIME NOT NULL default ' 2000-01-01 00:00:00 ',        ' endtime ' DATETIME default null,        ' issuccess ' int (one-by-one) default NULL,        ' duration ' int ( One) default null,        ' errormessage ' VARCHAR (+) default null,        ' Randno ' INT (one-by-one) default null    ) Engine=innodb DEFAULT Charset=utf8;  

 

Create a job based on the following build template

#请注意根据实际情况修改相关信息

DELIMITER $ $create definer= ' root ' @ '% ' EVENT ' job_backup_tb_cat ' on SCHEDULE every 1 day starts ' 2016-09-07 01:00:00 ' on CO   Mpletion not PRESERVE ENABLE does BEGIN DECLARE v_starttime DATETIME DEFAULT now ();      DECLARE v_randno INTEGER DEFAULT Floor (RAND () *100001);      DECLARE R_code CHAR (5) DEFAULT ' 00000 ';      DECLARE r_msg TEXT;    DECLARE V_error INTEGER;         INSERT into ' t_event_history ' (' starttime ', ' issuccess ', Randno) VALUES (V_starttime,0,v_randno);              Begin #异常处理段 DECLARE CONTINUE HANDLER for SQLEXCEPTION begin SET V_error = 1;          GET Diagnostics CONDITION 1 r_code = returned_sqlstate, r_msg = Message_text;  END;    #此处为实际调用的用户程序过程 call Backup_tb_cat ();   END; UPDATE t_event_history SET Endtime=now (), Issuccess=1,duration=timestampdiff (Second,starttime,now ()), errormessage=  CONCAT (' error= ', R_code, ', message= ', r_msg), Randno=null where Starttime=v_starttime and Randno=v_randno; end$ $DELIMITER;

  

By querying the T_event_history table, we know when the event is executed, whether the execution is successful, the execution time, and the error message when the error occurs, providing great convenience for managing our daily scheduling schedule.

MySQL Event monitoring log

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.