Archive for June, 2009

Checking/repairing all MySQL tables

Caution: on busy servers this will make a lot of load. Use only when you suspect/know tables are broken.


#!/usr/bin/perl

$mysql = "/var/lib/mysql";

@res = `cd $mysql; find .|grep MYD`;

foreach(@res) {
chomp;
/./(.*?)/(.*?).MYD/;
$tab = $1.".".$2;
print `mysql --execute='repair table $tab'`;
}