MySQL InnoDB のテーブルスペースを再構築するスクリプト

<?php

$url = "localhost";
$user = "root";
$pass = "";

$link = mysql_connect($url, $user, $pass);
$res = mysql_query("SHOW DATABASES");

while ($row = mysql_fetch_assoc($res)) {
    $db = $row['Database'];
    echo $db . "\n";
    mysql_select_db($db, $link);
    $res2 = mysql_query("SHOW TABLES");
    while ($row2 = mysql_fetch_assoc($res2)) {
       $table = $row2['Tables_in_'. $db];
       echo "  " .$table . "\n";
       mysql_query("ALTER TABLE " . $table . " ENGINE=InnoDB");
    }
}