1.查看是否开启evevt与开启evevt。

 1.1、MySQL evevt功能默认是关闭的,可以使用下面的语句来看evevt的状态,如果是OFF或者0,表示是关闭的。
show VARIABLES LIKE '%sche%';
1.2、开启evevt功能
SET GLOBAL event_scheduler = 1;
2.创建定时器的过程
2.1、创建测试表test
drop table if exists test;
create table test
(
id int(11) not null auto_increment primary key,
time datetime not null
) engine=innodb default charset=utf8;
2.2、创建evevt要调用的存储过程test_proce
delimiter //
drop procedure if exists test_proce//
create procedure test_proce()
begin
insert into test(time) values(now());
end//
delimiter ;
2.3、开启evevt(要使定时起作用,MySQL的常量GLOBAL event_scheduler必须为on或者是1)
执行show variables like 'event_scheduler';查看evevt是否开启;
若没开启执行set global event_scheduler='on';
2.4、创建事件test_event(其作用:每隔一秒自动调用test_proce()存储过程)
drop event if exists test_event;
create event test_event
on schedule every 1 second
on completion preserve disable
do call test_proce();
2.5、开启事件test_event
alter event test_event on completion preserve enable;
2.6、关闭事件test_event
alter event test_event on completion preserve disable;
2.7、查看表test
select * from test; 3.查看自己创建的event
如果要查看更加详细的信息,你需要root用户的授权,如果是你自己的数据库你可以用下面语句查看
select * from mysql.event;
下面的我的evevt的查看结果
mysql创建定时器(event),查看定时器,打开定时器,设置定时器时间 4.event的时间设置
设置event很简单,但是麻烦的是如何设置执行的时间,网上找了一些,自己总结了一下。
先看语句,如下面这个
CREATE EVENT test_event ON SCHEDULE EVERY 1 DAY STARTS '2012-09-24 00:00:00'
ON COMPLETION PRESERVE ENABLE DO CALL test_procedure();
EVERY 后面的是时间间隔,可以选 1 second,3 minute,5 hour,9 day,1 month,1 quarter(季度),1 year
从2013年1月13号0点开始,每天运行一次
ON SCHEDULE EVERY 1 DAY STARTS '2013-01-13 00:00:00'
从现在开始每隔九天定时执行
ON SCHEDULE EVERY 9 DAY STARTS NOW() ;
每个月的一号凌晨1 点执行
on schedule every 1 month starts date_add(date_add(date_sub(curdate(),interval day(curdate())-1 day),interval 1 month),interval 1 hour);
每个季度一号的凌晨1点执行
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);
每年1月1号凌晨1点执行
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);

Mysql 查看定时器 打开定时器 设置定时器时间的更多相关文章

  1. Linux系统运维笔记(一),查看系统版本和设置系统时间

    Linux系统运维笔记 查看系统版本和设置系统时间 查看系统版本 lsb_release -a (适用于所有的linux,包括Redhat.SuSE.Debian等发行版,但是在debian下要安装l ...

  2. mysql查询缓存打开、设置、参数查询、性能变量意思

    http://blog.sina.com.cn/s/blog_75ad10100101by7j.html http://www.cnblogs.com/zemliu/archive/2013/08/0 ...

  3. mysql查看sql语句的设置

    SHOW VARIABLES LIKE "general_log%"; SET GLOBAL general_log_file = 'D:\\mysql.log'; SET GLO ...

  4. 【MySQL】函数IFNULL、设置默认时间

    MySql 函数 IFNUll用法说明 IFNULL(expr1,expr2) 如果 expr1 不是 NULL,IFNULL() 返回 expr1,否则它返回 expr2. IFNULL()返回一个 ...

  5. MySQL 日期类型及默认设置 (除timestamp类型外,系统不支持其它时间类型字段设置默认值)

    MySQL 日期类型及默认设置 之前在用 MySQL 新建 table,创建日期类型列时遇到了一些问题,现在整理下来以供参考. MySQL 的日期类型如何设置当前时间为其默认值? 答:请使用 time ...

  6. 在vue组件中设置定时器和清除定时器

    由于项目中难免会碰到需要实时刷新,无论是获取短信码,还是在支付完成后轮询获取当前最新支付状态,这时就需要用到定时器.但是,定时器如果不及时合理地清除,会造成业务逻辑混乱甚至应用卡死的情况,这个时就需要 ...

  7. IOS 设置定时器

    IOS 设置定时器  自动滚动视图 定时发送坐标信息 即时显示 时钟 NSTimer *timer; - (void)start {//1second 调用一次 timer = [NSTimer sc ...

  8. IOS 设置定时器,执行方法

    //设置定时器(1秒后跳到一下题) [self performSelector:@selector(nextQuestion) withObject:nil afterDelay:1.0];

  9. 6.cocos2d设置定时器

    T1LayerAnchorPoint.h #pragma once #include "cocos2d.h" USING_NS_CC; class T1LayerAnchorPoi ...

随机推荐

  1. Service_name 和Sid的区别

    Service_name:该参数是由oracle8i引进的.在8i以前,使用SID来表示标识数据库的一个实例,但是在Oracle的并行环境中,一个数据库对应多个实例,这样就需要多个网络服务名,设置繁琐 ...

  2. game to refactor for refactor

    first step, only aim to work. it works, but i have not seen the necessaty to use class yet. my quest ...

  3. Redis Desktop Manager 利用ssh连接 Redis

    需开启6379端口,如果不设置密码,就忽略1,2步骤 第一步: 第二步: 第三步: 第四步: 第五步:

  4. P2147 [SDOI2008]洞穴勘测(LCT)

    P2147 [SDOI2008]洞穴勘测 裸的LCT. #include<iostream> #include<cstdio> #include<cstring> ...

  5. P2221 [HAOI2012]高速公路(线段树)

    P2221 [HAOI2012]高速公路 显然答案为 $\dfrac{\sum_{i=l}^r\sum_{j=l}^{r}dis[i][j]}{C_{r-l+1}^2}$ 下面倒是挺好算,组合数瞎搞 ...

  6. 探索RequestBody报com.alibaba.fastjson.JSONObject cannot be cast to xxx

    今天使用RequestBody接受前端传过来的参数,以前接受字符串数组非常成功,这次把形参改成了List<User>,原本以为顺利接受参数并映射成User的list结构,结果竟然在我取us ...

  7. sentos7为例添加python3和python2共存

    转载:https://www.cnblogs.com/JahanGu/p/7452527.html 1.查看是否已经安装Python CentOS 7.2 默认安装了python2.7.5 因为一些命 ...

  8. win-Linux文件脚本迁移过程中的问题 syntax error: unexpected end of file

    问题:  在win下写好的shell脚本,放到Linux上测试sh -n报错如下 ORA_check.sh: line 251: syntax error: unexpected end of fil ...

  9. pillow生成验证码

    1.结果 2.安装pillow cmd里进入python,pip install pillow,需要等一段时间 3.代码 from PIL import Image, ImageDraw, Image ...

  10. Selenium android driver

    selenium android « s « Jar File Download http://www.java2s.com/Code/Jar/s/selenium-android.htm How t ...