参考博客: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;