數據插入不覆蓋更新,設置定時任務

數據插入不覆蓋更新
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;
相關文章
相關標籤/搜索