zoukankan      html  css  js  c++  java
  • mysql中创建event定时任务

    从网上借鉴大神的。

    1. use onlinexam;  
    2. -- 查看event事件是否开启  
    3. show variables like '%sche%';  
    4. -- 开启event事件  (非常重要)
    5. set global event_scheduler =1;  
    6. -- 创建存储过程  
    7. -- 更新试卷状态的存储过程  
    8. drop procedure if exists update_paperstatus;  
    9. create procedure update_paperstatus()  
    10. begin  
    11. update oe_paper  
    12. set oe_paper_status='1'  
    13. where oe_paper_startime<=now()  
    14. and oe_paper_endtime>=now()  
    15. and oe_paper_status!='2';  
    16. update oe_paper  
    17. set oe_paper_status='3'  
    18. where oe_paper_endtime<now();  
    19. end;  
    20. -- 查看库中有哪些存储过程  
    21. show procedure status where Db='mytest';  
    22. show procedure status where Db='onlinexam';  
    23. -- 创建定时任务  
    24. -- 每60s执行一次  
    25. DROP EVENT IF EXISTS e_updatePaperStatus; -- 删除事件  
    26. create event if not exists e_updatePaperStatus  
    27. on schedule every 10 second  -- 设置10秒执行一次  
    28. starts date_add(now(),interval 10 second) -- 在10后执行  
    29. on completion preserve   
    30. do call update_paperstatus();  
    31. -- 开启事件任务  
    32. alter event e_updatePaperStatus ON  
    33. COMPLETION PRESERVE ENABLE;  
    34. -- 关闭事件任务  
    35. alter event e_updatePaperStatus ON  
    36. COMPLETION PRESERVE DISABLE;  
  • 相关阅读:
    获取yyyymmdd hh:ii:ss形式的日期时间
    详解SQL Server如何链接远程MySQL
    SET QUERY_GOVERNOR_COST_LIMIT
    STR函数将数字数据转换成字符数据
    表的转置
    C#中时间的Ticks属性
    创建CheckBox样式的下拉列表
    HTML DOM whiteSpace 属性
    TRUNCATE TABLE
    NFS服务配置.
  • 原文地址:https://www.cnblogs.com/webttt/p/7838001.html
Copyright © 2011-2022 走看看