我們可以拿來應用在最佳化所有資料表 OPTIMIZE TABLE~~
附上程式碼,以下只需更改 mysql_connect 即可使用
$dbh = mysql_connect('localhost', 'username', 'password');
$resource = mysql_query('SHOW DATABASES', $dbh);
echo 'Found ' . mysql_num_rows($resource) . " databases.";
while ($db_t = mysql_fetch_assoc($resource)) {
$db_name = $db_t['Database'];
echo "Database : $db_name";
mysql_select_db($db_name, $dbh);
$r = mysql_query('SHOW TABLE STATUS', $dbh);
while ($t = mysql_fetch_assoc($r)) {
echo $t['Name']."
";
if ($t['Data_free'] > 0) {
echo $t['Name'] . " optimization.\n";
mysql_query('OPTIMIZE TABLE ' . $t['Name'], $dbh) or die(mysql_error());
}
}
}
?>
沒有留言:
張貼留言