http://bugs.moodle.com/bug.php?op=show&bugid=113
It seems that (with MySQL at least) OPTIMIZE can cause problems:
http://www.mysql.com/doc/en/OPTIMIZE_TABLE.html
I´ve never heardabout this errors...
I´m Supportmanager from YaBB SE! We have about 3000 User using our software! And we have an integraded optimizing tool, what i wrote! also with db´s bigger as 50 mb or even 100 mb we run never in trouble!
<?
/*****************************************************************************/
/* dboptimizer.php */
/*****************************************************************************/
/* Software Distributed by: http://www.maincomm.de */
/* Support, News, Updates at:
/* ========================================================================= */
/* Copyright (c) 2001-2002 The mainComm DEV Team */
/* The maincomm DEV Team is: Manju, Medizinmann, Mediman */
/* Software by: The maincomm Dev Team */
/*****************************************************************************/
/* This program is free software; you can redistribute it and/or modify it */
/* under the terms of the GNU General Public License as published by the */
/* Free Software Foundation; either version 2 of the License, or (at your */
/* option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, but */
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General */
/* Public License for more details. */
/* */
/* The GNU GPL can be found in gpl.txt in this directory */
/*****************************************************************************/
//script for optimizing your database tables
//your database connection
//databasename, username, pwd, host
$dbName = "";
$dbUser = "";
$dbPass = "";
$dbHost = "localhost";
function getConnection($dbName, $dbUser, $dbPass, $dbHost){
$db = mysql_connect ( $dbHost, $dbUser, $dbPass );
mysql_select_db($dbName, $db) or die("Unable to select database");
return $db;
}
function closeConnection($db){
mysql_close($db);
}
$db = getConnection($dbName, $dbUser, $dbPass, $dbHost);
$query = "SHOW TABLE STATUS FROM ".$dbName;
$get_tables = mysql_query($query, $db);
$num_tabs = mysql_num_rows($get_tables);
echo "<font color=red>Your database contains $num_tabs! tables.<p></font>";
if(0 < $num_tabs){
echo "trying to optimize tables ... <p>";
$k = 0;
$i = 0;
while($table = mysql_fetch_array($get_tables, $db)){
$tableName = mysql_tablename($get_tables, $i);
$datalength = $table['Data_length'];
$indexlength = $table['Index_length'];
$length = $datalength + $indexlength;
$length = $length / 1024;
$length = round ($length, 3);
$freedata = $table['Data_free'];
$freedata = $freedata / 1024;
$freedata = round ($freedata, 3);
//optimize
$query = "OPTIMIZE TABLE ".$tableName;
$resultat = mysql_query($query, $db);
if($freedata == 0){ $k = $k + 1; }
else {
echo "<font color=red>optimize:</font> $tableName .... <font color=green>$freedata kb optimized</font><br>";
$opttab++;
}
$i++;
}
$cnt = $num_tabs - $k;
if($cnt == 0){ echo "<p><font color=green>all tables are optimized</font>"; }
else { echo "<p><font color=red>$opttab tables optimized</font>"; }
} // end if
closeConnection($db);
?>
Feel free to use it!
Btw: i think the trouble starts when you converts ISAM to MyISAM Tables and then starts optimizing...
André
I'm running serveral MySQL databases over here.
I was searching for a optimize script, but finaly I did the folowing:
Symlink /usr/bin/mysqlcheck to /usr/bin/mysqloptimize.
And then put it in cron like this:
3 0 * * 7 root /usr/bin/mysqloptimize -A > /dev/null
I run it once a week due to low transactions that cause overhead in the databases.
But you can run it every night.
Hope this helps.
Kind regards,
Huib