Mysql 查看定時器 開啟定時器 設定定時器時間

來源:互聯網
上載者:User

標籤:date()   開始   values   自動   rop   開啟   2.3   時間間隔   詳細   

 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 test11 (12 id int(11) not null auto_increment primary key,13 time datetime not null14 ) engine=innodb default charset=utf8;15 2.2、建立evevt要調用的預存程序test_proce16 delimiter //17 drop procedure if exists test_proce//18 create procedure test_proce()19 begin20 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_event29 on schedule every 1 second30 on completion preserve disable31 do call test_proce();32 2.5、開啟事件test_event33 alter event test_event on completion preserve enable;34 2.6、關閉事件test_event35 alter event test_event on completion preserve disable;36 2.7、查看錶test37 select * from test;38 39 3.查看自己建立的event40 如果要查看更加詳細的資訊,你需要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);

 

Mysql 查看定時器 開啟定時器 設定定時器時間

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.