mysql计划任务

这两天一直遇见mysql计划任务的案例,今天我就给大家分享一个真是的实例:

1、创建计划任务的语法:

create event 任务名称 on schedule  at 时间周期 starts '年-月-日 时-分-秒‘ do sql语句

或者

create event 任务名称 on schedule  every 时间周期 starts '年-月-日 时-分-秒‘ do sql语句

at 是在设置的时间中执行这条语句就不再执行了,而every 是一个循环的操作,比如我的时间设置的是'2015-05-08 17:55:00’,

at语句就是在这个2015-05-08 17:55:00时间点上执行,

而every 是在你设定的时间周期内重复执行这条语句。

2、查看计划任务执行状态:

 SELECT * FROM information_schema.EVENTS; 
我执行后的结果:

def test e_test root@localhost SYSTEM SQL TRUNCATE TABLE a RECURRING 1 DAY STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION 2015-05-06 13:15:12 ENABLED NOT PRESERVE 2015-05-06 13:13:28 2015-05-06 13:13:28 2015-05-08 13:15:12 0 utf8 utf8_general_ci latin1_swedish_ci
def mysql e_test root@localhost SYSTEM SQL UPDATE users SET name=1300001 WHERE id=529 RECURRING 1 DAY STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION 2015-05-06 13:53:00 ENABLED NOT PRESERVE 2015-05-06 13:52:12 2015-05-06 13:52:12 2015-05-08 13:53:00 0 utf8 utf8_general_ci latin1_swedish_ci
def own e_test root@localhost SYSTEM SQL UPDATE emp SET city=4444444 WHERE id=8888 RECURRING 1 DAY STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION 2015-05-06 15:26:00 ENABLED NOT PRESERVE 2015-05-07 15:03:38 2015-05-07 15:03:38 2015-05-08 15:26:00 0 utf8 utf8_general_ci latin1_swedish_ci
def own e_update root@localhost SYSTEM SQL UPDATE user SET score=0 WHERE isvalid=1 RECURRING 1 DAY STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION 2015-05-06 15:00:00 ENABLED NOT PRESERVE 2015-05-07 15:03:38 2015-05-07 15:03:38 2015-05-08 15:00:00 0 utf8 utf8_general_ci latin1_swedish_ci
def mysql users_score_update root@localhost SYSTEM SQL UPDATE users as a LEFT JOIN (select user_id,sum(score) as score from scorerecords
where isvalid=1 and convert(createtime,date) = CURDATE()
and score >0 group by user_id) as b on a.id = b.user_id
set a.dailyscore = case when b.score is null then 0 else b.score end
where a.isvalid =1 RECURRING 1 DAY STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION 2015-05-06 15:00:00 ENABLED NOT PRESERVE 2015-05-07 12:01:43 2015-05-07 12:01:43 2015-05-08 15:00:00 0 utf8 utf8_general_ci latin1_swedish_ci
def ceshi w_update root@% SYSTEM SQL UPDATE wuceshi SET name ='ddd' WHERE id=1 RECURRING 1 DAY STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION 2015-05-08 14:03:00 ENABLED NOT PRESERVE 2015-05-08 14:02:56 2015-05-08 14:02:56 2015-05-08 14:03:00 0 utf8 utf8_general_ci latin1_swedish_ci
def damayi users_score_update root@% SYSTEM SQL UPDATE users as a LEFT JOIN (select user_id,sum(score) as score from scorerecords
where isvalid=1 and convert(createtime,date) = CURDATE()
and score >0 group by user_id) as b on a.id = b.user_id
set a.dailyscore = case when b.score is null then 0 else b.score end
where a.isvalid =1 RECURRING 1 DAY STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION 2015-05-08 15:26:00 ENABLED NOT PRESERVE 2015-05-08 15:24:52 2015-05-08 15:24:52 2015-05-08 15:26:00 0 utf8 utf8_general_ci latin1_swedish_ci
def damayi e_test_insert root@% SYSTEM SQL INSERT INTO test.aaa VALUES (CURRENT_TIMESTAMP) RECURRING 1 SECOND STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION 2015-05-08 15:04:17 ENABLED NOT PRESERVE 2015-05-08 15:04:17 2015-05-08 15:04:17 2015-05-08 18:02:40 0 utf8 utf8_general_ci latin1_swedish_ci
def mayidaxiangcs users_score_update root@% SYSTEM SQL UPDATE users as a LEFT JOIN (select user_id,sum(score) as score from scorerecords
where isvalid=1 and convert(createtime,date) = CURDATE()
and score >0 group by user_id) as b on a.id = b.user_id
set a.dailyscore = case when b.score is null then 0 else b.score end
where a.isvalid =1 RECURRING 1 DAY STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION 2015-05-06 00:00:00 ENABLED NOT PRESERVE 2015-05-08 15:47:21 2015-05-08 15:47:21 0 utf8 utf8_general_ci latin1_swedish_ci
def ceshievent users_score_update root@% SYSTEM SQL UPDATE users as a LEFT JOIN (select user_id,sum(score) as score from scorerecords
where isvalid=1 and convert(createtime,date) = CURDATE()
and score >0 group by user_id) as b on a.id = b.user_id
set a.dailyscore = case when b.score is null then 0 else b.score end
where a.isvalid =1 RECURRING 1 DAY STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION 2015-05-06 00:00:00 ENABLED NOT PRESERVE 2015-05-08 16:57:36 2015-05-08 16:57:36 0 utf8 utf8_general_ci latin1_swedish_ci
def damayidaxiang users_score_update root@% SYSTEM SQL UPDATE users as a LEFT JOIN (select user_id,sum(score) as score from scorerecords
where isvalid=1 and convert(createtime,date) = CURDATE()
and score >0 group by user_id) as b on a.id = b.user_id
set a.dailyscore = case when b.score is null then 0 else b.score end
where a.isvalid =1 RECURRING 5 MINUTE STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION 2015-05-08 17:55:00 ENABLED NOT PRESERVE 2015-05-08 17:56:21 2015-05-08 17:56:21 2015-05-08 18:00:00 0 utf8 utf8_general_ci latin1_swedish_ci

 

 

 

你可能感兴趣的:(mysql)