search

Home  >  Q&A  >  body text

java - mysql automatically deletes data every other day

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梦2775 days ago1171

reply all(7)I'll reply

  • 迷茫

    迷茫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;  

    reply
    0
  • ringa_lee

    ringa_lee2017-06-16 09:21:28

    It is better to leave this logic to Java.

    reply
    0
  • 高洛峰

    高洛峰2017-06-16 09:21:28

    Use Java scheduled tasks.

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

    reply
    0
  • PHP中文网

    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

    reply
    0
  • 世界只因有你

    世界只因有你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

    reply
    0
  • PHP中文网

    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

    reply
    0
  • 怪我咯

    怪我咯2017-06-16 09:21:28

    Try quartz, I don’t know if it will help you

    reply
    0
  • Cancelreply