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. hdu1599 find the mincost route

    题目链接 floyd找最小环 很好理解 #include<algorithm> #include<iostream> #include<cstdlib> #incl ...

  2. jquery操作节点

    var v= $("input[type='checkbox'][name='ids']:checked").closest('tr').find('td:eq(2)').map( ...

  3. Django框架----命名URL和URL反向解析

    在使用Django 项目时,一个常见的需求是获得URL 的最终形式,以用于嵌入到生成的内容中(视图中和显示给用户的URL等)或者用于处理服务器端的导航(重定向等).人们强烈希望不要硬编码这些URL(费 ...

  4. The Little Prince-12/12

    The Little Prince-12/12 双十二,大家有没有买买买呢?宝宝双十一之后就吃土了,到现在,叶子都长出来了!!! 当你真的喜欢一个人的时候 就会想很多 会很容易办蠢事 说傻话 小王子要 ...

  5. thinkphp 检测验证码

    /** * 检测验证码 * @param integer $id 验证码ID * @return boolean 检测结果 */function check_verify($code, $id = 1 ...

  6. OL6.3 设置本地yum源

    仅在 Oracle Linux Server release 6.3 上测试 PS:Oracle Linux Server release 6.3仅用于测试,不能用于商业用途 [root@oracle ...

  7. 深入理解Word2Vec

    Word2Vec Tutorial - The Skip-Gram Model,Skip-Gram模型的实现原理:http://mccormickml.com/2016/04/19/word2vec- ...

  8. linux下安装与部署redis

    一.Redis介绍 Redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcache类似,但很大程度补偿了Memcache的不足,它支持存储的value类型相对更多 ...

  9. Codeforces 980E The Number Games - 贪心 - 树状数组

    题目传送门 传送点I 传送点II 传送点III 题目大意 给定一颗有$n$个点的树,$i$号点的权值是$2^{i}$要求删去$k$个点,使得剩下的点仍然连通,并且总权值和最大,问删去的所有点的编号. ...

  10. Codeforces 844D Interactive LowerBound - 随机化

    This is an interactive problem. You are given a sorted in increasing order singly linked list. You s ...