From: (Hal Date: January 26 2012 5:45pm Subject: Re: Script for cleaning data on a regular basis List-Archive: http://lists.mysql.com/mysql/226677 Message-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" >>>> 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.