Created
January 23, 2015 16:24
-
-
Save dgitman/051369274e99e3577a63 to your computer and use it in GitHub Desktop.
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/sh | |
mysql -NBe "SHOW DATABASES;" | grep -v 'lost+found' \ | |
| while read database ; do | |
#skip system-db | |
if [ "$database" = "mysql" ] ; then | |
continue | |
fi | |
mysql -NBe "SHOW TABLE STATUS;" $database \ | |
| while read name engine version rowformat rows avgrowlength \ | |
datalength maxdatalength indexlength datafree autoincrement \ | |
createtime updatetime checktime collation checksum \ | |
createoptions comment ; do | |
#skip views | |
if [ "$datafree" = "NULL" ] ; then | |
continue | |
fi | |
if [ "$datafree" -gt 0 ] ; then | |
echo "$database.$name is fragmented" | |
mysql -NBe "OPTIMIZE TABLE $name;" "$database" | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment