2 Star 31 Fork 9

码上开源/blind_date

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mysql事件方法.txt 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
码上开源 提交于 2020-09-04 15:14 . xiangxin init
1.查看事件状态
show variables like 'event_scheduler';
开启
set GLOBAL event_scheduler = 1;
SET GLOBAL event_scheduler = ON;
mysql 执行的命令
CREATE PROCEDURE Mypro() //创建存储过程
BEGIN
UPDATE member SET liwunum = 0 WHERE `grade` = 1;
END;
定时器任务
create event if not exists e_test
on schedule every 1 DAY starts timestamp '2017-04-24 01:00:00'
on completion preserve
do call Mypro();
//改进
on schedule every 1 DAY STARTS date_add(date(curdate() + 1),interval 0 hour) -- 每天凌晨执行
create event e_test
on schedule every 1 DAY starts timestamp '2017-04-24 15:40:00'
on completion preserve
do
UPDATE member SET liwunum = 0 WHERE `grade` = 1;
create event e_test
on schedule every 1 DAY STARTS date_add(date(curdate() + 1),interval 0 hour)
on completion preserve
do
UPDATE member SET liwunum = 0 WHERE `STATUS` = 0;
开启定时器任务
alter event e_test ON COMPLETION PRESERVE ENABLE;
关闭定时器任务
alter event e_test ON COMPLETION PRESERVE DISABLE;
语法很简单,如下所示:
DROP EVENT [IF EXISTS] event_name
例如删除前面创建的e_test事件
DROP EVENT e_test;
当然前提是这个事件存在,否则会产生ERROR 1513 (HY000): Unknown event错误,因此最好加上IF EXISTS
DROP EVENT IF EXISTS e_test;
查看定时器任务
select * from mysql.event
注意:真实的开发环境中,会遇到mysql服务重启或者断电的情况,此时则会出现事件调度器被关闭的情况,所有事件都不在起作用,要想解决这个办法,则需要在mysql.ini文件中加入event_scheduler = ON; 的语句
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/source_open/blind_date.git
[email protected]:source_open/blind_date.git
source_open
blind_date
blind_date
master

搜索帮助