MySQL定时刷新数据

一、步骤

1.查看定时策略是否开启,查看命令:
show variables like '%event_sche%';

2.显示的 event_scheduler 为 OFF 时用以下命令开启:
set global event_scheduler=1;

3.创建存储过程
use toursim_platform; -- 选择数据库toursim_platform
delimiter //
create procedure atrraction_proce()
begin
update attraction set numbers = '500' WHERE id = '01';
update attraction set numbers = '500' WHERE id = '02';
update attraction set numbers = '20000' WHERE id = '03';
update attraction set numbers = '5000' WHERE id = '04';
update attraction set numbers = '10000' WHERE id = '05';
update attraction set numbers = '20000' WHERE id = '06';
end//
delimiter ;

4.创建定时任务 event ( 事件 )
create event day_refresh_event
on schedule every 1 day        -- 每1天执行1次
on completion preserve disable
do call atrraction_proce();

-- 关闭事件任务
alter event day_refresh_event ON COMPLETION PRESERVE DISABLE; 
-- 开启事件任务 
alter event day_refresh_event ON COMPLETION PRESERVE ENABLE;  
-- 查看定时任务
SHOW EVENTS 
-- 删除事件任务
drop event if exists day_refresh_event

二、在navicat使用的步骤展示

 相关资料

学习来自该篇文章。可以实现,非常感谢,作者写的非常清晰明了。

MySQL 中的定时任务 | jiyiren

什么是 procedure ( 存储过程 ) ?

存储过程?当我听到这个词的时候,以为它是 MySQL 存储数据的一个流程而不是一个名词,但是当我网上了解时,才知道这个词是翻译过来的,原生词为 Procedure, 实际上它的含义就是相当于我们面向对象里的方法或者说是 函数,在它里面可以完成多个 sql 语句的操作,并且可以定义参数传值等,与一般的单条 sql 语句的区别主要在这里,详细了解 点我

猜你喜欢

转载自blog.csdn.net/weixin_46499784/article/details/130561304