MySQL archive records based on date column

Let's assume you have a logs table and you want to delete the logs which are more than 1 year old. Ideally you would like to automate this using a cron job. MySQL Between query [crayon-59ebd6bfcee5c719738515/] Using the above query we can delete all the logs for the year 2014. However we cannot automate this query since we are providing the dates manually. MySQL DATE_SUB query [crayon-59ebd6bfcee66488074924/] Above query deletes all the records which are older than a year. Here we do not need to provide dates. It automatically finds the records which are older than a year using NOW and INTERVAL parameters. So let's say you want to delete all the records which are 6 months old then the query would be [crayon-59ebd6bfcee6b551298523/] Now lets automate the process of archiving our logs table This can be done through a number of ways. Shell Script [crayon-59ebd6bfcee6f380191153/] A shell script can be created with above code. The script can then be added to a cron job. MySQL event scheduler Read more [crayon-59ebd6bfcee73675591320/] PHP Script Create a PHP page to run the query and...
Read More