如何建立一个数据库内的定时任务
工具:navicat工具
查看event是否开启: show variables like '%sche%';
将事件计划开启:
SET GLOBAL event_scheduler = ON;
SET @@global.event_scheduler = ON;
SET GLOBAL event_scheduler = 1;
(该操作需要操作用户有建立trigger的权限)
开户事件任务: alter event e_test ON COMPLETION PRESERVE ENABLE;
关闭事件任务: alter event e_test ON COMPLETION PRESERVE DISABLE;
创建event e_test
navicat工具的交互设定:
定义事件的语句:
CREATE DEFINER=`root`@`%` //定义者
EVENT e_test
ON SCHEDULE EVERY 10 MINUTE STARTS '2016-10-10 11:34:40' //定义计划
ON COMPLETION NOT PRESERVE
ENABLE //开启事件任务
DO
delete FROM zkread.user where email = 'zhaikeread@163.com'; //事件操作
查看创建的事件:
SHOW EVENTS;
删除一个事件:
DROP EVENT e_test;