bitscn.com
1.创建存储过程。
2.创建事件(定时执行存储过程)。
举例,如有表student 字段有id、name、age、login_time(登录时间);
每30秒更新登录时间为当前时间。
(1)创建student表。
(2)创建存储过程pro_student:
begin
update student set login_time=now();
end
保存
(3)创建事件e_student
create event if not exists e_student
on schedule every 30 second
on completion preserve
do call pro_student();
3.如果没有生效则查看event和事件任务是否开启:
查看event是否开启: show variables like %sche%;
将事件计划开启: set global event_scheduler=1;
关闭事件任务: alter event e_test on completion preserve disable;
开户事件任务: alter event e_test on completion preserve enable;
在创建作业时报以下错误,
在打开数据库时客户端提示“cannot proceed because system tables used by event scheduler were found damaged at server start”
造成此原因是mysql服务器的当前版本不兼容所有数据库的表
解决方法
1、linux、windows下解决方法类似
$path /mysql_upgrade -u root -p
例如:/usr/local/mysql/bin/mysql_upgrade - u root -p [回车输入密码即可]
$path mysql安装路径 我这里是用的(d:wampinmysqlmysql5.1.30in)
执行完后停止mysqld后再重新启动mysqld一次,问题即可解决。
bitscn.com
