文章会有【原创】或者【转载】标示,部分来自Google Baidu的学习结果 {Java/PHP/Python/Ruby/Go}

MySQL计划任务【学习】  


转载学习:http://www.oschina.net/question/4873_20927
show version(); // 版本 大于5.1

show variables like '%event%';
event_scheduler | OFF

SET GLOBAL event_scheduler = ON; //开启计划任务

SELECT * FROM mysql.event\G //查看目前运行的计划任务

use test //先创建test数据库

CREATE TABLE aaa (t TIMESTAMP);
CREATE EVENT e_test_insert
ON SCHEDULE EVERY 1 SECOND
DO INSERT INTO test.aaa VALUES (CURRENT_TIMESTAMP);



5天后清空表
CREATE EVENT e_test
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 5 DAY
DO TRUNCATE TABLE test.aaa;

每天定时清空表

CREATE EVENT e_test
ON SCHEDULE EVERY 1 DAY
DO TRUNCATE TABLE test.aaa;


删除计划任务
drop event e_test_insert;