• Mysql 查看定时器 打开定时器 设置定时器时间


     1 1.查看是否开启evevt与开启evevt。
     2 
     3 1.1、MySQL evevt功能默认是关闭的,可以使用下面的语句来看evevt的状态,如果是OFF或者0,表示是关闭的。
     4               show VARIABLES LIKE '%sche%';
     5 1.2、开启evevt功能
     6             SET GLOBAL event_scheduler = 1;
     7 2.创建定时器的过程
     8 2.1、创建测试表test
     9 drop table if exists test;
    10 create table test
    11 (
    12 id int(11) not null auto_increment primary key,
    13 time datetime not null
    14 ) engine=innodb default charset=utf8;
    15 2.2、创建evevt要调用的存储过程test_proce
    16 delimiter //
    17 drop procedure if exists test_proce//
    18 create procedure test_proce()
    19 begin
    20 insert into test(time) values(now());
    21 end//
    22 delimiter ;
    23 2.3、开启evevt(要使定时起作用,MySQL的常量GLOBAL event_scheduler必须为on或者是1)
    24 执行show variables like 'event_scheduler';查看evevt是否开启;
    25 若没开启执行set global event_scheduler='on';
    26 2.4、创建事件test_event(其作用:每隔一秒自动调用test_proce()存储过程)
    27 drop event if exists test_event;
    28 create event test_event
    29 on schedule every 1 second
    30 on completion preserve disable
    31 do call test_proce();
    32 2.5、开启事件test_event
    33 alter event test_event on completion preserve enable;
    34 2.6、关闭事件test_event
    35 alter event test_event on completion preserve disable;
    36 2.7、查看表test
    37 select * from test;
    38 
    39 3.查看自己创建的event
    40 如果要查看更加详细的信息,你需要root用户的授权,如果是你自己的数据库你可以用下面语句查看
    41 select * from  mysql.event;
    42 下面的我的evevt的查看结果
    43 mysql创建定时器(event),查看定时器,打开定时器,设置定时器时间
    44 
    45 4.event的时间设置
    46 设置event很简单,但是麻烦的是如何设置执行的时间,网上找了一些,自己总结了一下。
    47 先看语句,如下面这个
    48      CREATE EVENT test_event ON SCHEDULE EVERY 1 DAY STARTS '2012-09-24 00:00:00'
    49      ON COMPLETION PRESERVE ENABLE DO CALL test_procedure();
    50 EVERY 后面的是时间间隔,可以选 1 second,3 minute,5 hour,9 day,1 month,1 quarter(季度),1 year 
    51 从2013年1月13号0点开始,每天运行一次
    52 ON SCHEDULE EVERY 1 DAY STARTS '2013-01-13 00:00:00'
    53 从现在开始每隔九天定时执行
    54 ON SCHEDULE EVERY 9 DAY STARTS NOW() ;
    55 每个月的一号凌晨1 点执行
    56 on schedule every 1 month starts date_add(date_add(date_sub(curdate(),interval day(curdate())-1 day),interval 1 month),interval 1 hour);
    57 每个季度一号的凌晨1点执行
    58 on schedule every 1 quarter starts date_add(date_add(date(concat(year(curdate()),'-',elt(quarter(curdate()),1,4,7,10),'-',1)),interval 1 quarter),interval 1 hour);
    59 每年1月1号凌晨1点执行
    60 on schedule every 1 quarter starts date_add(date_add(date(concat(year(curdate()),'-',elt(quarter(curdate()),1,4,7,10),'-',1)),interval 1 quarter),interval 1 hour);
  • 相关阅读:
    ThinkPHP-5.0.23新的RCE漏洞测试和POC
    利用DNS日志进行MySQL盲注
    Prometheus自动发现
    relabel_config
    Maven安装
    Redis安装
    Node.js安装
    MySQL-5.7安装
    设计模式【1】------>单例模式
    Java设计模式概念以及六大设计原则
  • 原文地址:https://www.cnblogs.com/wang-yaz/p/9591742.html
Copyright © 2020-2023  润新知