having a mysql optimise cron job

txt3rob

Verified User
Joined
Jan 16, 2007
Messages
101
i need to keep a database optimised as i get errors but after i run the optimiser from the ELS script everything goes fine so i need help in putting it in as a cron job.

can any only help me add a command that will run mysql optimisation every night?
 
im temped to run this

Code:
// Change these four variables to match your configuration.
// You will probably only need to change “user”, “pwd” and “dbName”.
$server = ”localhost”;
$user = ”mysql_user”;
$pwd = ”mysql_password”;
$dbName = ”mysql_dbName”;

$link = mysql_connect($server, $user, $pwd);
if (!$link) {
die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db($dbName, $link);
if (!$db_selected) {
die ('Can\'t use $dbName : ' . mysql_error());
}

// Find the names of all tables in the selected db.
$alltables = mysql_query("SHOW TABLES");

// Go through all tables.
while ($table = mysql_fetch_assoc($alltables))
{
foreach ($table as $db => $tablename)
{
// Perform the magic “OPTIMIZE” on every table in the db.
mysql_query("OPTIMIZE TABLE '".$tablename."'")
or die(mysql_error());
}

}

mysql_close($link);
?>
 
or this
Code:
mysqlcheck -Aao .auto-repair -u root -ppassword > /dev/null

which would any one suggest?
 
Back
Top