Search code examples
phpmysqlcronsql-delete

Delete MySQL information in table using Cron jobs


I am using cPanel, trying to use cron jobs to delete all data in a table, but when I went to cron jobs in cPanel, I got an error when I put in the following:

DELETE FROM patron_joined WHERE uid < NOW() - INTERVAL 1 MINUTE

I checked my email for completion of the cron job and received the following message:

/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `DELETE FROM patron_joined WHERE uid < NOW() - INTERVAL 1 
MINUTE'

I have been researching this issue for the last 2 hours and I haven't found any information on how to run a cron job from cPanel to delete all info in a table.

The database is named tragicco_patron and the table is patron_joined. Any help is greatly appreciated!


Solution

  • You have to invoke CLI mysql-client like this:

    0 23 * * * * root /usr/bin/mysql -e "USE mydatabase; DELETE FROM patron_joined WHERE uid < NOW() - INTERVAL 1 MINUTE;"