mysql
How to automatically delete data after the specified time
I am using
java
to make a to-do item andmysql
to make the database
I want to automatically delete completed rows the next day
Replenish
Compare the timestamp I set with the current time, and then delete it
Because I am using se, the database is only opened when it is usedSorry, I didn’t write the question clearly.
迷茫2017-06-16 09:21:28
You can create a scheduled task for mysql
1. Check whether the event is open
show variables like '%sche%';
Enable event_scheduler
set global event_scheduler =1;
2. Create stored procedure test
CREATE PROCEDURE test ()
BEGIN
update userinfo set endtime = now() where id = '110';
END;
3. Create event e_test
create event if not exists e_test
on schedule every 30 second
on completion preserve
do call test();
The stored procedure test will be executed every 30 seconds
Close event task
alter event e_test ON COMPLETION PRESERVE DISABLE;
Account opening event task
alter event e_test ON COMPLETION PRESERVE ENABLE;
高洛峰2017-06-16 09:21:28
Use Java scheduled tasks.
import java.util.Timer;
import java.util.TimerTask;
PHP中文网2017-06-16 09:21:28
Solve it with java
@schedule(cron = "0 0 0 * ?" ) Execute a scheduled task at zero o'clock every day
There is one asterisk missing between the 0 and the asterisk above. Two asterisks in a row will be blocked
世界只因有你2017-06-16 09:21:28
I tend to use scripts to operate, but mysql also provides its own stored procedures, which are essentially executed by simple mysql statements.
I checked the advantages and disadvantages of stored procedures on the Internet, and then you think about the advantages and disadvantages of scripts, which method to use, make your own choice!
Advantages and disadvantages of stored procedures
PHP中文网2017-06-16 09:21:28
1.mysql's own task scheduling Event
2.java application layer task scheduling, QuartZ is recommended
3. Write scripts, Node, python can be used, using the task scheduling of the operating system