Home  >  Article  >  Database  >  mysql 让一个存储过程定时作业_MySQL

mysql 让一个存储过程定时作业_MySQL

WBOY
WBOYOriginal
2016-06-01 13:51:47882browse

   以下例子主要是实现简单的mysq 定时作业

  1、在mysql 中建立一个数据库 test1

   语句:create database test1

2、创建表examinfo

create table examinfo(
id int auto_increment not null,
endtime datetime,
primary key(id)
);

3 插入数据:

  insert  into examinfo values('1','2011-4-23 23:26:50');

4 创建存储过程test

     CREATE PROCEDURE test () <br />     BEGIN <br />          update examinfo SET endtime = now() WHERE id = 1; <br />     END; <br />5、<pre class="reply-text mb10">  创建event e_test <br />     CREATE EVENT if not exists e_test <br />          on schedule every 30 second <br />          on completion preserve <br />     do call test(); <br />6、<pre class="reply-text mb10">查看event是否开启: show variables like '%sche%'; <br />将事件计划开启: set global event_scheduler=1; <br />关闭事件任务: alter event e_test ON COMPLETION PRESERVE DISABLE; <br />开户事件任务: alter event e_test ON COMPLETION PRESERVE ENABLE; <br />7、运行查询结果即可出现想要的结果。<br /><br />结果显示如下:<br /> 原始数据:<br />   <img  src="http://img.bitscn.com/upimg/allimg/c140719/1405M242106250-911Z.jpg" / alt="mysql 让一个存储过程定时作业_MySQL" ><br />过一段时间查询后的数据:<br /> <img  src="http://img.bitscn.com/upimg/allimg/c140719/1405M242135940-101045.jpg" / alt="mysql 让一个存储过程定时作业_MySQL" ><br /><br />
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn