java - mysql automatically deletes data every other day
过去多啦不再A梦
过去多啦不再A梦 2017-06-16 09:19:28
0
7
1161

mysqlHow to automatically delete data after the specified time

I am using java to make a to-do item and mysql 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 used

Sorry, I didn’t write the question clearly.

过去多啦不再A梦
过去多啦不再A梦

reply all(7)
迷茫

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;  
左手右手慢动作

It is better to leave this logic to Java.

小葫芦

Use Java scheduled tasks.

import java.util.Timer;
import java.util.TimerTask;
Ty80

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template