PHP Script to Optimize All Tables In A MySQL Database

In MYSQL OPTIMIZE TABLE should be used if you have deleted a large part of a table or if you have made many changes to a table with variable-length rows. Deleted rows are maintained in a linked list and subsequent INSERT operations reuse old row positions. You can use OPTIMIZE TABLE to reclaim the unused space and to defragment the data file.

OPTIMIZE TABLE statement requires SELECT and INSERT privileges for the table.

This PHP script will optimize all the tables in a particular mysql database.

//Database connection
$alltbls = mysql_query("show tables");
while ($table = mysql_fetch_assoc($alltbls))
foreach ($table as $db => $tablename)
mysql_query("OPTIMIZE TABLE '".$tablename."'")
or die(mysql_error());

Related Posts:

One Responses

Ganga October 22, 2008 at 5:17 am

grt information

Comments are closed.