mysql 讓一個(gè)存儲(chǔ)過程定時(shí)作業(yè)的代碼
更新時(shí)間:2011年05月07日 23:41:20 作者:
以下例子主要是實(shí)現(xiàn)簡單的mysq 定時(shí)作業(yè),需要的朋友可以參考下。
1、在mysql 中建立一個(gè)數(shù)據(jù)庫 test1
語句:create database test1
2、創(chuàng)建表examinfo
create table examinfo(
id int auto_increment not null,
endtime datetime,
primary key(id)
);
3 插入數(shù)據(jù):
insert into examinfo values('1','2011-4-23 23:26:50');
4 創(chuàng)建存儲(chǔ)過程test
CREATE PROCEDURE test ()
BEGIN
update examinfo SET endtime = now() WHERE id = 1;
END;
5、 創(chuàng)建event e_test
CREATE EVENT if not exists e_test
on schedule every 30 second
on completion preserve
do call test();
6、查看event是否開啟: show variables like '%sche%';
將事件計(jì)劃開啟: set global event_scheduler=1;
關(guān)閉事件任務(wù): alter event e_test ON COMPLETION PRESERVE DISABLE;
開戶事件任務(wù): alter event e_test ON COMPLETION PRESERVE ENABLE;
7、運(yùn)行查詢結(jié)果即可出現(xiàn)想要的結(jié)果。
結(jié)果顯示如下:
原始數(shù)據(jù):

過一段時(shí)間查詢后的數(shù)據(jù):
語句:create database test1
2、創(chuàng)建表examinfo
create table examinfo(
id int auto_increment not null,
endtime datetime,
primary key(id)
);
3 插入數(shù)據(jù):
insert into examinfo values('1','2011-4-23 23:26:50');
4 創(chuàng)建存儲(chǔ)過程test
CREATE PROCEDURE test ()
BEGIN
update examinfo SET endtime = now() WHERE id = 1;
END;
5、 創(chuàng)建event e_test
復(fù)制代碼 代碼如下:
CREATE EVENT if not exists e_test
on schedule every 30 second
on completion preserve
do call test();
6、查看event是否開啟: show variables like '%sche%';
將事件計(jì)劃開啟: set global event_scheduler=1;
關(guān)閉事件任務(wù): alter event e_test ON COMPLETION PRESERVE DISABLE;
開戶事件任務(wù): alter event e_test ON COMPLETION PRESERVE ENABLE;
7、運(yùn)行查詢結(jié)果即可出現(xiàn)想要的結(jié)果。
結(jié)果顯示如下:
原始數(shù)據(jù):

過一段時(shí)間查詢后的數(shù)據(jù):
您可能感興趣的文章:
- 詳解MySQL用事件調(diào)度器Event Scheduler創(chuàng)建定時(shí)任務(wù)
- mysql的定時(shí)任務(wù)實(shí)例教程
- Linux下如何實(shí)現(xiàn)Mysql定時(shí)任務(wù)
- Linux下Mysql定時(shí)任務(wù)備份數(shù)據(jù)的實(shí)現(xiàn)方法
- mysql定時(shí)任務(wù)(event事件)實(shí)現(xiàn)詳解
- mysql實(shí)現(xiàn)設(shè)置定時(shí)任務(wù)的方法分析
- MySQL定時(shí)執(zhí)行腳本(計(jì)劃任務(wù))命令實(shí)例
- 逐步講解MySQL中定時(shí)事件計(jì)劃的創(chuàng)建
- MySQL定時(shí)器開啟、調(diào)用實(shí)現(xiàn)代碼
- mysql自動(dòng)定時(shí)備份數(shù)據(jù)庫的最佳方法(windows服務(wù)器)
- mysql 定時(shí)任務(wù)的實(shí)現(xiàn)與使用方法示例
相關(guān)文章
MySQL數(shù)據(jù)庫備份和還原的常用命令小結(jié)
MySQL數(shù)據(jù)庫備份和還原的常用命令小結(jié),學(xué)習(xí)mysql的朋友可以參考下2012-03-03
Mysql中日期和時(shí)間函數(shù)應(yīng)用不用求人
Mysql中日期和時(shí)間函數(shù)應(yīng)用不用求人,學(xué)習(xí)mysql的朋友可以參考下。2010-11-11
MySQL實(shí)現(xiàn)差集(Minus)和交集(Intersect)測試報(bào)告
MySQL沒有實(shí)現(xiàn)Minus和Intersect功能,就像它也沒有實(shí)現(xiàn)cube的功能一樣。2014-06-06

