zoukankan      html  css  js  c++  java
  • mysql的定时任务

    参考博客:https://blog.csdn.net/qq_26562641/article/details/53301407

    查看event是否开启: show variables like '%sche%';  

    event_scheduler ON                         --------》表示已开启
    performance_schema OFF
    performance_schema_events_waits_history_long_size 10000
    performance_schema_events_waits_history_size 10
    performance_schema_max_cond_classes 80

    .........

    将事件计划开启: set global event_scheduler=1;  临时开启(mysql服务重启后之后失效)

    永久开启:

    在my.cnf或my_default.ini中的[mysqld]部分添加如下内容,然后重启mysql(mysql重启命令:service mysqld restart)

    event_scheduler=ON

    关闭事件任务: alter event e_test ON COMPLETION PRESERVE DISABLE; 
    开户事件任务: alter event e_test ON COMPLETION PRESERVE ENABLE; 

    查看任务列表

    SELECT * FROM information_schema.events; 

    创建一个简单的计划任务,这里调用的是存储过程。do 后面也可以跟sql

    //从现在起每30s执行一次这个存储过程

     CREATE EVENT if not exists e_test 
              on schedule every 30 second 
              on completion preserve 
         do call test(); 

    //每天凌晨一点执行存储过程

    CREATE EVENT IF NOT EXISTS temp_event 
    ON SCHEDULE EVERY 1 DAY STARTS DATE_ADD(DATE_ADD(CURDATE(), INTERVAL 1 DAY), INTERVAL 1 HOUR) 
    ON COMPLETION PRESERVE ENABLE 
    DO update users set support=0 where support=1;

    关闭定时任务temp_event

    DROP event temp_event;

  • 相关阅读:
    【解题报告】2019正睿Day2
    如何卡SPFA
    【游记】2019国庆清北刷题营
    CF427D Match & Catch
    P2178 [NOI2015] 品酒大会
    Loj#6071. 「2017 山东一轮集训 Day5」字符串
    SP8093 JZPGYZ
    P3346 [ZJOI2015]诸神眷顾的幻想乡
    CF1037H Security
    CF932F Escape Through Leaf
  • 原文地址:https://www.cnblogs.com/coder-lzh/p/9419765.html
Copyright © 2011-2022 走看看