<?

include_once '../inc/start_sess.php';

$at = mysql_query('SHOW TABLES');  //получим список таблиц
while ($tables = mysql_fetch_assoc($at)) 
{ 
   foreach ($tables as $bd => $table) 
   { 
       mysql_query('OPTIMIZE TABLE `'.trim($table).'`')
           or die(mysql_error()); 
   }  
} 
?>