forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
#!/usr/bin/php -q |
|
<?php |
|
# NAME: VacuumMysqlDatabase.php |
|
# DEVELOPER: Alvin Alexander, http://devdaily.com |
|
# COPYRIGHT: |
|
# LICENSE: Copyright 2010, Alvin Alexander. |
|
# This software is released under the terms of the |
|
# Creative Commons Share-Alike License. See the following |
|
# URL for more information: |
|
# http://creativecommons.org/licenses/by-sa/3.0/ |
|
# database parameters |
|
$db_host = '127.0.0.1'; |
|
$db_user = 'root'; |
|
$db_pass = ''; |
|
$db_dbname = 'pbx'; |
|
|
|
# show all errors right now |
|
error_reporting(E_ERROR); |
|
ini_set("display_errors", 'Off'); |
|
|
|
# connect to database |
|
$link = mysql_connect($db_host, $db_user, $db_pass); |
|
if (!$link) { |
|
die('Could not connect: ' . mysql_error()); |
|
} |
|
mysql_select_db($db_dbname); |
|
|
|
# vacuum all the mysql tables |
|
$alltables = mysql_query("SHOW TABLES"); |
|
while ($table = mysql_fetch_assoc($alltables)) { |
|
foreach ($table as $db => $tablename) { |
|
mysql_query("OPTIMIZE TABLE $tablename") or die(mysql_error()); |
|
} |
|
} |
|
|
|
# need root access (or similar) to run this command |
|
mysql_query("FLUSH TABLES") or die(mysql_error()); |
|
?>
|