mysqlタイマ(EVENT)は、毎日のゼロポイントでストレージ・プロシージャを実行します.

1002 ワード

--         
show procedure status;

--     resetMsgNum()    
--        update sc_user SET msg_num = 0;
create procedure resetMsgNum()
BEGIN
update sc_user SET msg_num = 0;
end;

--     eventResetMsgNum 
drop event if EXISTS eventResetMsgNum;
--     
SHOW EVENTS;

--   mysql    event:
-- create event if not exists eventResetMsgNum
-- on schedule 
-- every 20 second 
-- on completion PRESERVE
-- do call resetMsgNum();

--      (event) eventResetMsgNum 
--         '2019-6-12 23:06:00'
--      1 / 
--      resetMsgNum();
create event eventResetMsgNum  
on schedule 
EVERY 1 day  
STARTS '2019-6-12 23:06:00'  
do call resetMsgNum();

-- mysql         mysql        :
SET GLOBAL event_scheduler = 1;  --      
SET GLOBAL event_scheduler = 0;  --      

--       :
ALTER EVENT eventResetMsgNum ON  COMPLETION PRESERVE ENABLE;   --     
ALTER EVENT eventResetMsgNum ON  COMPLETION PRESERVE DISABLE;  --     

SHOW VARIABLES LIKE '%sche%'; --