Delete a row from a database table after a certain time period [duplicate]

     
  

This question already has an answer here:

     
  



i'm working on a database driven website and i'm using WAMP
is it possible with mysql to automatically delete a row from the table below when the registrationDate is old by - for example - a month?

Thank you


ID | Name | registrationDate    1 | client1 | 2017-05-09 05:23:16   2 | client2 | 2017-05-11 12:13:30   
  
"
answer1
  
  

You could use an event eg:


CREATE EVENT deleteEachMonth  ON SCHEDULE EVERY 1 DAY STARTS '2017-05-01 00:00:00'  -- !!! no *END*: will continue until you explicitly drop the event  DO   DELETE FROM my_table WHERE my_date < DATE_SUB(curdate() INTERVAL 1 MONTH);  

in your case


CREATE EVENT deleteEachMonth   ON SCHEDULE EVERY 1 DAY STARTS '2017-05-01 00:00:00'   DO   DELETE FROM client WHERE registrationDate < DATE_SUB(curdate()