Skip to content

Instantly share code, notes, and snippets.

@lorello
Created December 21, 2015 16:08
Show Gist options
  • Select an option

  • Save lorello/26c51004301ca38d706e to your computer and use it in GitHub Desktop.

Select an option

Save lorello/26c51004301ca38d706e to your computer and use it in GitHub Desktop.
mysql rebuild indexes
#!/bin/bash
#
# Rebuild indexes on a single table or in a whole database
#
DB=$1
TABLES=$2
function syntax() {
echo -e "\nSYNTAX\n\t$0 <dbname> [\"table1 table2 table3 ...\"]\n\n"
}
[ -z $DB ] && syntax && exit 1
if [ -z "$TABLES" ]; then
TABLES=$(mysql -e "show tables;" -ss $DB)
fi
while read -r TABLE; do
mysql $DB -s -e "repair table $TABLE quick;"
done <<< "$TABLES"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment