How do I delete rows of data from mysql table automatically with 24 hours after data into table?

后端 未结 2 552
夕颜
夕颜 2020-12-17 04:59

For example, i have a data input program And I want to delete my data automatically after 1 day of this data I input. how I do that?
Someone can explain in code?

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-17 05:15

    In your table "portofolio" add column created_at(datetime). Then in Cron Job, check the current datetime exceeds created_at(datetime) with 24hours and delete the records by mysql query like

    DELETE FROM portofolio WHERE created_at<=DATE_SUB(NOW(), INTERVAL 1 DAY)
    

    And run the cron job file every minute

提交回复
热议问题