-1

anyone have idea to make event that can auto delete some record 3 days ago in mysql?

Nurudin
  • 3
  • 1
  • 2
    you can have a cronjob :) – Medda86 Jul 16 '16 at 08:07
  • use SQL Server Agent or refer this link http://stackoverflow.com/questions/18275386/how-to-automatically-delete-records-in-sql-server-after-a-certain-amount-of-time – Udhay Titus Jul 16 '16 at 08:08
  • You can check [**this**](http://stackoverflow.com/questions/36175959/how-to-automatically-delete-every-x-minutes). Using `MySQL Event Scheduler` you can accomplish this. – 1000111 Jul 16 '16 at 08:12
  • Write a php script, which will run daily via cron process to delete events which are 3 days old. – Shrikant Mavlankar Jul 16 '16 at 08:13

1 Answers1

0

If you have a field that stores the date of the update records, you can use MySql Event Sheduler.

Run in console:

SET GLOBAL event_scheduler=ON;

And to create an event, such as:

CREATE EVENT myevent
       ON SCHEDULE EVERY 3 DAY
       DO DELETE FROM mytable WHERE mytable.update_date <= (DATE_SUB(current_date(), INTERVAL 3 DAY));

See more: https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html

buildok
  • 785
  • 6
  • 7