简体   繁体   中英

How I can run mysql query automatically in every 1 hour?

I've integer value in my database and I want to decrease it with every passing hour. How can I do it?

You don't need to decrement the value. You can just store the base value and create a view to calculate the value one the fly. Something like this:

create table hourly (
    base_value int,
    starttime datetime
);

Then:

create view v_hourly
    select base_value - timestampdiff(hour, starttime, now())
    from hourly;

The alternative is to set up a job that runs each hour to decrement the value, but that is not necessary.

You could use the mysql event scheduler. You can find more information and examples here: https://dev.mysql.com/doc/refman/5.7/en/create-event.html

if you have used MySQL then please create cronJOB. if you have used SQL then please create Scheduler.

And set time and execute stored procedure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM