查看定时任务是否开启:
):
show variables like 'event_scheduler';
开启定时任务:
set global event_scheduler = on;
定时更新
ON COMPLETION [NOT] PRESERVE :表示当事件不会再发生的情况下,删除事件(注意特定时间执行的事件,如果设置了该参数,执行完毕后,事件将被删除,不想删除的话可以设置成ON COMPLETION PRESERVE);
ENABLE:表示系统将执行这个事件;
DROP EVENT IF EXISTS `event_at`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` EVENT `event_at` ON SCHEDULE AT '2018-04-14 19:01:00' ON COMPLETION PRESERVE ENABLE DO
BEGIN
UPDATE wxfeeling SET isPrivate=0;
END
;;
DELIMITER ;
当然如果不想打代码可以在可视化工具内管理:
项目(笔记):
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` EVENT `event_at` ON SCHEDULE EVERY 1 DAY STARTS '2018-04-14 00:00:00' ON COMPLETION PRESERVE ENABLE DO
BEGIN
UPDATE userinfomation SET secondsOfSong=0;
END
;;
DELIMITER ;
项目(笔记2
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` EVENT `event_activity` ON SCHEDULE EVERY 7 DAY STARTS '2018-04-09 00:00:00' ON COMPLETION PRESERVE ENABLE DO
BEGIN
DELETE FROM activity;
END
;;
DELIMITER ;
):