如何在 MySQL 中调度存储过程 [英] How to schedule a stored procedure in MySQL

查看:39
本文介绍了如何在 MySQL 中调度存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个存储过程.例如,我如何以 5 秒的间隔运行它?像消除时间戳超过一天的数据的例程吗?

I have this stored procedure. How can I run this for example with intervals of 5 seconds? Like a routine for eliminate data with a time-stamp older than one day?

DROP PROCEDURE IF EXISTS `delete_rows_links` 
GO

CREATE PROCEDURE delete_rows_links
BEGIN 

    DELETE activation_link
    FROM activation_link_password_reset
    WHERE  TIMESTAMPDIFF(DAY, `time`, NOW()) < 1 ; 

END 

GO

推荐答案

您可以使用 mysql 调度程序每 5 秒运行一次.您可以在 http://dev.mysql.com/doc/refman/5.1 找到示例/en/create-event.html

You can use mysql scheduler to run it each 5 seconds. You can find samples at http://dev.mysql.com/doc/refman/5.1/en/create-event.html

从未使用过它,但我希望这会奏效:

Never used it but I hope this would work:

CREATE EVENT myevent
    ON SCHEDULE EVERY 5 SECOND
    DO
      CALL delete_rows_links();

这篇关于如何在 MySQL 中调度存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆