mysql內置計劃任務學習 Java代碼 www.2cto.com 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;