1、工具:Navicat
2、通过下列语句l爱查询event是否开启
打开Navicat命令列界面(点击工具可以看到或按F6) 输入下面命令
show variables like '%sche%';

3、如果图中event_scheduler 为 OFF 通过执行下列语句,来开启event_scheduler
set global event_scheduler =1;
4、新建函数,选择过程,编辑sql语句,即定时执行的操作
点击新建函数->

选择过程->

填写名称(test2)->完成->编辑sql->保存

点击函数看到刚才创建的过程

5、创建事件,写入call test1(刚才创建的过程名称),点击计划,设置执行开始时间及频率

每5秒执行一次,2017-12-06 14:35:00为开始时间(注意格式) 保存

6、如未执行,执行下面命令开启事件
ALTER EVENT 你的事件名称 ENABLE;
纯命令创建MySQL定时任务
1、进入mysql 开启event_schduler;
set global event_scheduler =1;
show variables like '%event%';

2、进入数据库kawadai(测试数据库为kawadai)创建存储过程
use kawadai;
create procedure delete_log() delete from kd_log where create_time < unix_timestamp(now());

测试 存储过程
call delete_log()

3、创建Event事件
create event `my_test_event` on schedule every 30 second on completion preserve enable do call delete_log();

4、对于Event的常用操作
查看:SHOW EVENTS;
开启事件:
ALTER EVENT my_test_event ON COMPLETION PRESERVE ENABLE;
关闭事件:
ALTER EVENT my_test_event ON COMPLETION PRESERVE DISABLE;
删除事件:
DROP EVENT IF EXISTS my_test_event;
网友评论