数据插入不覆盖更新
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;