Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql event set up template (can record implementation resume)

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Establish a resume sheet

CREATE TABLE `mysql`.`t _ event_ Secrety` (`dbname` VARCHAR) NOT NULL DEFAULT', `eventname` NOT NULL DEFAULT', `starttime` DATETIME NOT NULL DEFAULT '0000-00-0000: 00NOT NULL DEFAULT, `endtime` DATETIME DEFAULT NULL, `istime` INT (11) DEFAULT NULL, `duration` INT (11) DEFAULT NULL, `errormessage` VARCHAR (512) DEFAULT NULL, `Randno` INT (11) DEFAULT NULL, PRIMARY KEY (`dbname`, `eventname`, `starttime`), KEY `ix_ endtime` (`endtime`), KEY `ix_starttime_ Randno` (`starttime`, `Randno`) ENGINE=INNODB DEFAULT CHARSET=utf8

2.event build template

DELIMITER $$CREATE DEFINER= `root` @ `localhost` EVENT `localhost` ON SCHEDULE # modify the following scheduling information EVERY 5 minute STARTS now () ON COMPLETION PRESERVE ENABLE DO BEGIN DECLARE r_code CHAR (5) DEFAULT '00000mm; DECLARE r_msg TEXT; DECLARE v_error INTEGER; DECLARE v_starttime DATETIME DEFAULT NOW (); DECLARE v_randno INTEGER DEFAULT FLOOR (RAND () * 100001) INSERT INTO mysql.t_event_history (dbname,eventname,starttime,randno) # modify the following job name (the name of the job) VALUES (DATABASE (), 'job_update_status', vault starttimejour vandranno) BEGIN # exception handling segment DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN SET v_error = 1; GET DIAGNOSTICS CONDITION 1 r_code = RETURNED_SQLSTATE, r_msg = MESSAGE_TEXT; END # here is the actual user program procedure CALL automaintain.pro_update_status (); END; UPDATE mysql.t_event_history SET endtime=NOW (), issuccess=ISNULL (v_error), 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

3. Query event

Select * from mysql.event

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report