Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql event set up template (can record implementation resume)

Shulou Source: shulou.com Published: 2022-06-01 06:38:48 10月03日 Update

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

Tags: Assignment resume template information name actual user program record table process face-to-face processing query scheduling Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft Linux Huawei MySQL