Run a mySQL query as a cron job?

后端 未结 4 1964
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 11:12

I would like to purge my SQL database from all entires older than 1 week, and I\'d like to do it nightly. So, I\'m going to set up a cron job. How do I query mySQL without h

4条回答
  •  野性不改
    2020-11-27 11:21

    Try creating a shell script like the one below:

    #!/bin/bash
    
    mysql --user=[username] --password=[password] --database=[db name] --execute="DELETE FROM tbl_message WHERE DATEDIFF( NOW( ) ,  timestamp ) >=7"
    

    You can then add this to the cron

提交回复
热议问题