a job to delete rows older than 3 months in mysql database

后端 未结 4 1770
走了就别回头了
走了就别回头了 2021-02-01 06:44

We use mysql server as a centralized logging system and I want to have a job to delete\\clean the table entries that are more than 3 months old regularly. What is the best way t

4条回答
  •  悲&欢浪女
    2021-02-01 07:22

    Do you store the date an item is created in a field?

    If so,

    DELETE FROM myTable WHERE dateEntered < DATE_SUB(NOW(), INTERVAL 3 MONTH);
    

    should work...

    You could run it in a scheduled task/cron job...

提交回复
热议问题