Re: Optimize Tables

From: Date: Tue, 04 May 2004 04:05:27 +0000
Subject: Re: Optimize Tables
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-34264@lists.php.net to get a copy of this message
Thanx for this enlightening insight about cron jobs... just a question.. when i run Optimize.php, i realise that you will echo some statements. where will these statements be shown? since you put " > /dev/null " instead of " > /dev/null 2>&1 ", does it mean that your echo statements will be reflected in an email to me? thanx.. i'm totally new to cron jobs, but thanx to sebastian's link on crontab, i'm a little bit more knowledgable now! haha.. would appreciate more insights! thanx! ----- Original Message ----- From: "Uzi Klein" <uzi@topmedic.co.il> To: "'Ng Hwee Hwee'" <hhwee@towa.com.sg>; "'DBList'" <php-db@lists.php.net> Sent: Monday, May 03, 2004 6:32 PM Subject: RE: [PHP-DB] Optimize Tables > Use a cron job.... > > Like: > > 0 0 * * * php Optimize.php > /dev/null > > > This is an example for optimizing every table in all databases on your mysql > server. > > Optimize.php : > > <?php > $db = mysql_connect("host", "user", "pass"); > $sql = "SHOW DATABASES"; > $dbs_result = mysql_query($sql, $db); > if(mysql_num_rows($dbs_result)) > { > while($dbs_row=mysql_fetch_assoc($dbs_result)) > { > $database = $dbs_row["Database"]; > echo "\n\nOptimizing database $database : \n"; > mysql_select_db($database, $db); > $sql = "SHOW TABLE STATUS"; > $tbls_result = mysql_query($sql, $db); > if(mysql_num_rows($tbls_result)) > { > while($tbls_row=mysql_fetch_assoc($tbls_result)) > { > $TableName = > "".$tbls_row["Name"].""; > $sql = "REPAIR TABLE ".$TableName; > echo "\n".$sql; > mysql_query($sql, $db); > $sql = "OPTIMIZE TABLE ".$TableName; > echo "\n".$sql; > mysql_query($sql, $db); > } > } > } > } > echo "\n\n"; > mysql_close($db); > ?> > > > -----Original Message----- > From: Ng Hwee Hwee [mailto:hhwee@towa.com.sg] > Sent: Monday, May 03, 2004 11:19 > To: DBList > Subject: [PHP-DB] Optimize Tables > > Hi, > > Is there a way to create a schedule to optimise my MySQL tables > automatically? The overhead of some of my tables can reach 355,548 bytes > over 3 working days! > > Please help me! > > Thanks. > Hwee > >

« previous php.db (#34264) next »