当前位置:Gxlcms > 数据库问题 > MySQL 添加定时执行任务

MySQL 添加定时执行任务

时间:2021-07-01 10:21:17 帮助过:5人阅读

create procedure myfunc() -> begin -> delete from information where id > 2; -> end//

创建过程,begin 和 end 之间就是该过程的内容

mysql> create event del_info
    -> on schedule every 600 second starts timestamp 2020-05-14 18:28:00
    -> on completion preserve
    -> do
    -> begin
    -> call myfunc();
    -> end//

创建定时任务 del_info:

每600秒执行一次,起始时间点为  2020-05-14 18:28:00

完成后,该任务保留, 不保留可以使用  on completion not preserve

 

执行

begin和end之间为执行的内容

call myfunc()    执行上面定义的过程

最后需要把 SQL语句终结符号改回来

delimiter ;

然后使用 show events;命令,就能查看到刚刚添加定时任务

 删除过程和事件(任务)

mysql> drop event del_info;
Query OK, 0 rows affected (0.00 sec)

mysql> show events;
Empty set (0.00 sec)

mysql> drop procedure myfunc;
Query OK, 0 rows affected (0.00 sec)

 

MySQL 添加定时执行任务

标签:HERE   creat   www   执行   语句块   inf   命令   RoCE   drop   

人气教程排行