How to set a timer in mysql

2020-04-21 05:24发布

Suppose the current date is 20141110 10:00pm , I would like to let mysql to update a field and then dump few fields into a file while the date is 20141201 10:00pm

how to implement it?

What I know is to use event, but this seems to be used under some interval time. like every few hours/days/weeks to make the event happen.

3条回答
仙女界的扛把子
2楼-- · 2020-04-21 05:54

Mysql events is good option or you can use database triggers if you have older version of mysql.

http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html http://www.mysqltutorial.org/mysql-triggers/working-mysql-scheduled-event/

查看更多
唯我独甜
3楼-- · 2020-04-21 05:56

You can declare a fixed point in time for the event's schedule. The interval part is optional.

Here's an example that appears on manual page http://dev.mysql.com/doc/refman/5.6/en/create-event.html

mysql> CREATE EVENT e_totals
    ->     ON SCHEDULE AT '2006-02-10 23:59:00'
    ->     DO INSERT INTO test.totals VALUES (NOW());

Note also that you do not have to use a stored procedure.

查看更多
时光不老,我们不散
4楼-- · 2020-04-21 06:09

You will need a stored procedure to execute the code. It is a place where you can have if/else/white.......working with sp

Then you will need an event to call the procedure at any schedule time.

You have to make sure event-scheduler is turned on in mysql

查看更多
登录 后发表回答