Here is a simple script for optimizing MySQL table. You will need to set the username and password for a user with "admin" like privileges.
use DBI;
$dbi_host="localhost";
# all databases
@dbi_u=("admin_user");
@dbi_p=("qwerty");
#set the max count value
$ending_value = scalar(_at_dbi_u);
#loop throuogh each of the above databases
for($counter=0 ; $counter < $ending_value ; $counter++){
# connect to data input table
$dbh_in = DBI->connect("dbi:mysql:host=$dbi_host", $dbi_u[$counter], $dbi_p[$counter], { RaiseError => 0, AutoCommit => 1 }) or die "cannot connect to server" . $DBI::errstr;
$sth_dbs = $dbh_in -> prepare("SHOW DATABASES");
$sth_dbs -> execute();
for($loop_db=0; $loop_db<$sth_dbs -> rows; $loop_db++){
@row = $sth_dbs -> fetchrow_array;
# databases with a '-' in their name are not handled very well
if (index($row[0], '-') == -1){
# gen query
$sth = $dbh_in -> prepare("SHOW TABLES FROM ".$row[0]);
$sth -> execute();
$query = "";
for($loop_t=0; $loop_t<$sth -> rows; $loop_t++) {
@row2 = $sth -> fetchrow_array;
if ($query eq ""){
$query = "OPTIMIZE TABLE ";
}else{
$query .= ", ";
}
$query .= $row[0].".".$row2[0];
}
# skip databases without tables
if ($query ne ""){
print "Optimizing ".$row[0]."...\n";
$sth = $dbh_in -> prepare($query);
$sth -> execute();
}
}
}
}
All it does it loop through each database and optimise the tables. I would suggest a simple weekly or monthly cron job to execute the script. The script though will e-mail the cron user a list of optimised databases - simply add " >/dev/null 2>&1" to the end of the crontab line to send the data to nowhere.
Titanpoker
europa casino
فوركس أونلاين
casino tropez
titan poker
Leave a Comment
Category Cloud
Link Dump Tag Cloud
Today: Wednesday, 07 January 2009
Categories
- AJAX (1) [atom | rss]
- General (1) [atom | rss]
- Joomla (2) [atom | rss]
- Linux Backups (1) [atom | rss]
- Miscellaneous (1) [atom | rss]
- MySQL (2) [atom | rss]
- PHP Programming (1) [atom | rss]
- Zend Framework (1) [atom | rss]
Main Menu
Articles
Tools
FileBrowser
![]() |
Applications |
![]() |
Computer_Forensics |
![]() |
Computer_Law |
![]() |
Cryptography_and_E-Commerce |
![]() |
Internet_Security |
![]() |
Joomla |
![]() |
Miscellaneous |
![]() |
Network_Security |
![]() |
Security_Management |
![]() |
Systems_Administration |
![]() |
Web_Development |
Blog Archives
- June 2007 (10)
Online Visitors:1
Today Visitors:9
Total Visitors:6209


