码迷,mamicode.com
首页 > 其他好文 > 详细

数据插入不覆盖更新,设置定时任务

时间:2018-11-14 14:16:05      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:删除   eve   pre   定时执行   alt   创建   计划   ike   com   

数据插入不覆盖更新
INSERT INTO user_role(
user_id,
role_id,
type,
is_del
)SELECT
zgh as user_id,
126 as role_id,
2 as type,
0 as is_del
FROM sugon_jzg_jbxx b
where not exists (select 1 from user_role a where a.user_id=b.zgh)
 
查看event是否开启
show variables like ‘%sche%‘;
 
将事件计划开启
set global event_scheduler=1;
 
创建存储过程add_user_role
CREATE PROCEDURE add_user_role()
BEGIN
INSERT INTO user_role(
user_id,
role_id,
type,
is_del
)SELECT
zgh as user_id,
126 as role_id,
2 as type,
0 as is_del
FROM sugon_jzg_jbxx b
where not exists (select 1 from user_role a where a.user_id=b.zgh);
END;
 
每天定时执行任务,设置第一次执行时间为‘2018-11-15 03:00:00‘,并且每天执行一次
create event if not exists e_add_user_role
on schedule every 1 day starts ‘2018-11-15 03:00:00‘
do call add_user_role();
 
查询任务
select * from mysql.event
 
关闭事件任务
alter event e_add_user_role ON COMPLETION PRESERVE DISABLE;
 
开启事件任务
alter event e_add_user_role ON COMPLETION PRESERVE ENABLE;
 
删除任务计划
drop event if exists e_add_user_role;
 
 

数据插入不覆盖更新,设置定时任务

标签:删除   eve   pre   定时执行   alt   创建   计划   ike   com   

原文地址:https://www.cnblogs.com/liquan-anran/p/9957293.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!