MySQL定时计划事件的使用

Note

  • show variables like 'event%'; 查看event_scheduler是否开启

  • set global event_scheduler =1; 开启事件计划

  • 创建存储过程

  • 1
    2
    3
    4
    create procedure test()
    BEGIN
    update user_info set update_time = now() where id = 1;
    END;
  • 创建事件(每隔30s执行存储过程test)

    1
    2
    3
    4
    create event if not exists e_test 
    on schedule every 30 second
    on completion preserve
    do call test();