Skip to content

Instantly share code, notes, and snippets.

@pad92
Created September 17, 2013 12:32
Show Gist options
  • Save pad92/6593720 to your computer and use it in GitHub Desktop.
Save pad92/6593720 to your computer and use it in GitHub Desktop.
A tester
#!/usr/bin/env sh
# === CONFIG ===
MYCNF='/etc/mysql/debian.cnf'
BIN_DEPS='bzip2 mysql'
# === CHECKS ===
for BIN in $BIN_DEPS; do
which $BIN 1>/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: Required file could not be found: $BIN"
exit 1
fi
done
# === CORE ===
for BDD in `mysql --defaults-extra-file=$MYCNF --skip-column-names -B -e "SHOW databases;" | egrep -v "^information_schema$|^performance_schema$"`; do
echo "* Processing BDD $BDD"
for TABLE in `mysql --defaults-extra-file=$MYCNF --skip-column-names -B $BDD -e "SHOW TABLES;" | grep -v slow_log | grep -v general_log`; do
echo " ** Optimize $BDD.$TABLE"
mysql --defaults-file=$MYCNF -e "optimize table $BDD.$TABLE"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment