Kevmeister
Kevmeister

Reputation: 147

Require Cron syntax for MySQL maintenance

I'm trying to set up a Cron job for deleting MySQL records where a date field is older than three weeks, but I can't figure out what the string is that goes in the box. Here's a pic of the Cron management screen. Can anyone help please? http://i46.tinypic.com/id4nsj.jpg

Upvotes: 1

Views: 172

Answers (1)

TheLastCicada
TheLastCicada

Reputation: 26

If you know the query you want to run, you can use the -e argument for mysql at the command line for your script. So the "Command to Run" in your cron management tool would be:

mysql -u <username> -p<password> -h <name-of-mysql-server> <databasename> 
-e "<YOUR-QUERY-HERE>"

The general structure of a query to delete records older than a date is:

DELETE FROM [table] WHERE [column] < DATE_SUB(NOW(), INTERVAL 3 WEEK);

Upvotes: 1

Related Questions