文章目录
准备
是否开启
select @@event_scheduler;
-- ON
show variables like 'event_scheduler';
Variable_name | Value |
---|---|
event_scheduler | ON |
任务
创建
-- DROP EVENT IF EXISTS sync_mtrols_hourly;
CREATE
DEFINER=`test`@`localhost`
EVENT IF NOT EXISTS sync_mtrols_hourly
ON SCHEDULE EVERY 1 HOUR
ON COMPLETION NOT PRESERVE
COMMENT 'sync matter_info roleids to matter_exam each hour.'
DO
UPDATE matter_exam me
INNER JOIN
matter_info mi ON me.id = mi.id
SET
me.role_ids = mi.role_ids
WHERE
mi.role_ids IS NOT NULL;
调整
- 调整为每天执行一次
ALTER EVENT sync_mtrols_hourly ON SCHEDULE EVERY 1 DAY;
禁用
ALTER EVENT sync_mtrols_hourly DISABLE;
激活
ALTER EVENT sync_mtrols_hourly ENABLE;
删除
DROP EVENT IF EXISTS sync_mtrols_hourly;
查看
- 当前用户的任务
SHOW EVENTS FROM test;
- 指定用户指定任务的创建语句
SHOW CREATE EVENT test.sync_mtrols_hourly ;
历史和参考
links
mysql事件计划自动_MySQL计划任务(事件调度器) Event Scheduler介绍