*查看所有事件*/
show events;
select * from mysql.event
/*查所有事件状态*/
show VARIABLES LIKE '%sche%';
/*查事件调度器当前状态*/
SELECT @@event_scheduler;
/*事件调度器开启1或on 开启*/
set global event_scheduler =1;
/*事件调度器关闭0或off 关闭*/
set global event_scheduler =0;
/*关闭事件任务e_test事件名称*/
alter event e_test on completion preserve DISABLE;
/*开启事件任务e_test事件名称*/
alter event e_test on completion preserve enable;
/*开启事件任务*/
/*创建表*/
drop table if exists student;
create table student
(
id int AUTO_INCREMENT,
stuname varchar(50),
bordate datetime,
primary key (id)
)
/*创建存储过程*/
create procedure p_addstudent()
BEGIN
INSERT into student(stuname,bordate)VALUES('jack',NOW());
END
/*创建事件*/
drop event if exists e_test;
create event e_test
on schedule every 1 day STARTS '2015-06-28 00:05:00'
on completion preserve
do
call p_addstudent();
/*从2015-06-28 01:00:00开始 每一秒执行一次*/
on schedule every 1 second STARTS '2015-06-28 01:00:00'
/*从2015-06-28 01:00:00开始 每一分执行一次*/
on schedule every 1 minute STARTS '2015-06-28 01:00:00'
/*从2015-06-28 01:00:00开始 每一小时执行一次*/
on schedule every 1 hour STARTS '2015-06-28 01:00:00'
/*every 1 day 每一天执行一次, starts 开始执行时间*/
on schedule every 1 day STARTS '2015-06-28 00:05:00'
/*从2015-06-28 01:00:00开始 每一个月执行一次*/
on schedule every 1 month STARTS '2015-06-28 01:00:00'
/*从2015-06-28 01:00:00开始 每一个季度执行一次*/
on schedule every 1 quarter STARTS '2015-06-28 01:00:00'
/*从2015-06-28 01:00:00开始 每一年执行一次*/
on schedule every 1 year STARTS '2015-06-28 01:00:00'
/*每个月的一号凌晨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);
转载于:https://my.oschina.net/u/1989488/blog/471447