Skip to content

Instantly share code, notes, and snippets.

@mlutfy
Created January 10, 2013 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlutfy/4504900 to your computer and use it in GitHub Desktop.
Save mlutfy/4504900 to your computer and use it in GitHub Desktop.
<?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