Created
January 20, 2014 17:01
-
-
Save MarcosBL/8524039 to your computer and use it in GitHub Desktop.
Simple MyISAM tables optimization - Just put it on a cron
This file contains 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 | |
# Get a list of all fragmented tables | |
FRAGMENTED_TABLES="$( mysql -e ';use information_schema; SELECT TABLE_SCHEMA,TABLE_NAME FROM TABLES WHERE ENGINE="MyISAM" AND TABLE_SCHEMA NOT IN ("information_schema","mysql") AND Data_free > 0' | grep -v "^+" | sed 's,\t,.,' )" | |
for fragment in $FRAGMENTED_TABLES; do | |
database="$( echo $fragment | cut -d. -f1 )" | |
table="$( echo $fragment | cut -d. -f2 )" | |
[ $fragment != "TABLE_SCHEMA.TABLE_NAME" ] && echo "Optimizando $fragment" && mysql -e "USE $database; OPTIMIZE TABLE $table;" > /dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment