Created
December 21, 2015 16:08
-
-
Save lorello/26c51004301ca38d706e to your computer and use it in GitHub Desktop.
mysql rebuild indexes
This file contains hidden or 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
| #!/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