From: walter harms Date: January 27 2012 12:17pm Subject: Re: Script for cleaning data on a regular basis List-Archive: http://lists.mysql.com/mysql/226687 Message-Id: <4F2295F0.70105@bfs.de> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Am 26.01.2012 18:45, schrieb HalXsz SXndor: >>>>> 20120126 10:34 AM +0200, a bv >>>> > Database contains > tables (structures?) which gets montly data , and these tables are > named as > > name1_name2_ yearmonth . I only want to have the whole database system > for last 2 years, and automaticly clean the data which became more > than 2 years old , so i need a script for this (shell, php etc) . Can > you please help me for this script ? and also which mysql command must > be used drop, trunk? > <<<<<<<< > You can, if you are careful, write an SQL procedure for dropping the appropriate tables. Since MySQL has no table variables, if you do this you will need PREPARE. > > Therefore, it well may be easier to do it all in PHP, since therewith you can construct statements. The statement "SHOW TABLES" is also a reference to table INFORMATION_SCHEMA.TABLES; maybe you can use "SHOW TABLES" for a SELECT statement in PHP; if not, try INFORMATION_SCHEMA.TABLES for their names. > > This is simple, consult your manual about crontab. and start a script like that: #!/bin/bash mysql -BAN database <