zoukankan      html  css  js  c++  java
  • 数据插入不覆盖更新,设置定时任务

    数据插入不覆盖更新
    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;
     
     
  • 相关阅读:
    [AGC001F] Wide Swap
    [SCOI2016]幸运数字
    [POI2014]HOTHotels 加强版
    [JSOI2008]球形空间产生器
    JZOJ 3167.查税
    0linux简介
    vmware15pro安装ubuntu18.10时出现显示不全问题
    02目录
    linux系统的基础优化
    1安装操作系统
  • 原文地址:https://www.cnblogs.com/liquan-anran/p/9957293.html
Copyright © 2011-2022 走看看