Created
January 10, 2013 19:15
-
-
Save mlutfy/4504900 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Read login credentials from the aegir conf. | |
global $aliases; | |
require "/var/aegir/.drush/server_localhost.alias.drushrc.php"; | |
if (! isset($aliases['server_localhost'])) { | |
die("alias not found for server_localhost"); | |
} | |
$creds = array_map('urldecode', parse_url($aliases['server_localhost']['master_db'])); | |
$mysqli = new mysqli($creds['host'], $creds['user'], $creds['pass']); | |
if ($mysqli->connect_error) { | |
die('Connect error ' . $mysqli->connect_errno . ': ' . $mysqli->connect_error); | |
} | |
// Get a listing of databases | |
$ignoredb = array( | |
'information_schema', | |
'mysql', | |
); | |
$optimizedb = array(); | |
$result = $mysqli->query("SHOW DATABASES"); | |
while ($record = $result->fetch_object()) { | |
if (! in_array($record->Database, $ignoredb)) { | |
$optimizedb[] = $record->Database; | |
} | |
} | |
// Optimize each table by running 'alter table foo engine=innodb' | |
print "START: " . date('r') . "\n"; | |
foreach ($optimizedb as $db) { | |
$mysqli->select_db($db); | |
$result = $mysqli->query("SHOW TABLES"); | |
while ($record = $result->fetch_assoc()) { | |
// Ex: [Tables_in_exampledb] => nodes | |
foreach ($record as $key => $val) { | |
$mysqli->query('ALTER TABLE ' . $val . ' ENGINE=InnoDB'); | |
print $db . '.' . $val . ': ' . date('r') . "\n"; | |
} | |
} | |
} | |
$mysqli->close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment