MySQL8计划任务

文章目录

准备

是否开启

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事件计划自动_MySQL计划任务(事件调度器) Event Scheduler介绍

CREATE EVENT Statement

SHOW EVENTS Statement

SHOW CREATE EVENT Statement

上一篇:兄弟,干了这杯Flink SQL !!!


下一篇:Linux Shell 实验总结及知识拓展(操作系统)