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;  
  • 相关阅读:
    SQL 查询第n条到第m条的数据
    Linq 中查询一个表中指定的字段
    归并排序与逆序对
    补码拾遗
    堆排序
    It is time to cut the Gordian Knot!
    蛋疼
    [引]Microsoft Visual Studio .NET 2005 预发行版
    关于VS2005中自动生成TableAdapter的事务处理
    关于释放ASPNET进程的内存占用问题.
  • 原文地址:https://www.cnblogs.com/webttt/p/7838001.html
Copyright © 2011-2022 走看看