mysql 儲存過程 定時任務

2021-06-25 17:21:07 字數 1261 閱讀 4985

/*

*建立儲存過程**/

create procedure if not exists test()

begin

insert into test.test (time) values( curdate() );

end;

set global event_scheduler=0;  //設定任務器 開關 1開 0關  

show variables like 'event_scheduler'; //檢視任務器

//建立定時任務 

create event if not exists event_test

on schedule every 30 second   //設定任務執行間隔時間

do call test();

//呼叫儲存過程

schedule:

//在某個時間點(+間隔時間)

at timestamp [+ interval interval]

| every interval [starts timestamp] [ends timestamp]

//間隔時間執行  

interval:

quantity

1) 每秒插入一條記錄到資料表

1use test;

2  createtable aaa (timeline timestamp);

3  createevent e_test_insert

4   onschedule every 1 second

5   do insertinto test.aaa values(current_timestamp);

2) 5天後清空test表:

1create event e_test

2   onschedule at current_timestamp + interval 5 day

3   do truncatetable test.aaa;

3) 2023年7月20日12點整清空test表:

1create event e_test

2   onschedule at timestamp '2007-07-20 12:00:00'

3   do truncatetable test.aaa;

4) 每天定時清空test表:

1create event e_test

2   onschedule every 1 day

3   do truncatetable test.aaa;

mysql定時任務與儲存過程例項

檢視event是否開啟 show variables like event sche 將事件計畫開啟 set global event scheduler 1 將事件計畫關閉 set global event scheduler 0 關閉事件任務 alter event eventname on c...

MySQL 建立儲存過程及定時任務

建立定時任務名為 event csdn 2019 01 01 00 00 00 起每10s 執行 create event if not exists event csdn on schedule every 10 second starts timestamp 2019 01 01 00 00 0...

Oracle定時任務呼叫儲存過程

刪除core,cmnet,sp,miq,4張表一周之前的資料 create or replace procedure del alarm others cancel info as begin delete m core cancel where sysdate 7 ttime delete m c...