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.
You can create a scheduled task for mysql
1. Check whether the event is open
Enable event_scheduler
2. Create stored procedure test
3. Create event e_test
The stored procedure test will be executed every 30 seconds
Close event task
Account opening event task
It is better to leave this logic to Java.
Use Java scheduled tasks.
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
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
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
Try quartz, I don’t know if it will help you