日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

mysql查看是否开启定时器_Mysql 查看定时器 打开定时器 设置定时器时间

發布時間:2023/12/19 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql查看是否开启定时器_Mysql 查看定时器 打开定时器 设置定时器时间 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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查看是否开启定时器_Mysql 查看定时器 打开定时器 设置定时器时间的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。