GetDotted Domains

Viewing Thread:
"Optimizing MySQL tables"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Fri 18/09/09 at 00:02
Regular
Posts: 595
Hi,

I was wondering...

Is there a way to optimize all the tables in a database in one hit, instead of going into the structure of each table and hitting Optimize?

Neil
Fri 18/09/09 at 16:02
Regular
Posts: 595
Ahhh well - nice try.

Thanks anyway.

:(

N.
Fri 18/09/09 at 15:57
Staff Moderator
"Aargh! Broken..."
Posts: 1,408
Ah yes sorry forgot you'd be restricted. You have to use the table optimisation feature in phpMyAdmin then I'm afraid.
Fri 18/09/09 at 02:03
Regular
Posts: 595
Thanks for that code Eccles.

After one or two syntax corrections I got:

Query : Access denied for user '******'@'localhost' to database 'mysql'

(Username removed)

Neil
Fri 18/09/09 at 00:42
Staff Moderator
"Aargh! Broken..."
Posts: 1,408
There is no single SQL statement that can do that in MySQL. However you could try this code:
<?php
set_time_limit(100);

$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;

// Connection variables edit for you VIP MySQL details
$host = 'localhost';
$user = 'vip_mysql';
$password = 'vip_mysql_password';
$vip_database_name = vip_database';

$dummy_db = 'mysql';
$db_link = mysql_connect($host,$user,$password);

$result = mysql_db_query($dummy_db, "SHOW TABLE STATUS FROM `".$vip_database_name."`", $db_link) or die('Query : ' . mysql_error());
$to_optimize = array();
while($rec = mysql_fetch_array($res)) {
if($rec['Data_free'] > 0) {
$to_optimize[] = $rec['Name'];
echo $rec['Name'] . 'needs to be optimized."n";
}
}
if(count($to_optimize) > 0) {
foreach($to_optimize as $tbl) {
mysql_db_query($vip_database_name, "OPTIMIZE TABLE `".$tbl."`", $db_link);
}
}

$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 6);
echo 'Optimisation completed. Total run time: '.$total_time.' secs'."n";
?>
. I've not had time to test it so can't guarantee it will work! The usual warnings regarding using the code at your own risk apply of course!
Fri 18/09/09 at 00:02
Regular
Posts: 595
Hi,

I was wondering...

Is there a way to optimize all the tables in a database in one hit, instead of going into the structure of each table and hitting Optimize?

Neil

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Just a quick note to say thanks for a very good service ... in fact excellent service..
I am very happy with your customer service and speed and quality of my broadband connection .. keep up the good work . and a good new year to all of you at freeola.
Matthew Bradley
Best Provider
The best provider I know of, never a problem, recommend highly
Paul

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.