MySQL定时任务(每天凌晨3点钟执行)
MySQL定时任务(每天凌晨3点钟执行)
//创建测试表
DROP table IF EXISTS demo;
CREATE TABLE demo (timeline TIMESTAMP );
//为测试表,创建定时任务(每天凌晨3点钟,插入数据)
DROP EVENT IF EXISTS event_demo_insert;
CREATE EVENT event_demo_insert
on schedule EVERY 1 DAY STARTS date_add(date(curdate() + 1),interval 3 hour)
do INSERT INTO demo value(CURRENT_TIMESTAMP);
修正后的代码:
//创建测试表
DROP table IF EXISTS demo;
CREATE TABLE demo (timeline TIMESTAMP );
//为测试表,创建定时任务(每天凌晨3点钟,插入数据)
DROP EVENT IF EXISTS event_demo_insert;
CREATE EVENT event_demo_insert
on schedule EVERY 1 DAY STARTS date_add(date( ADDDATE(curdate(),1)),interval 3 hour)
do INSERT INTO demo value(CURRENT_TIMESTAMP);