-
-
Save spalenza/94f358329f14395378944f2ff7f4ea33 to your computer and use it in GitHub Desktop.
Show largest tables (optionally, in a specific DB)
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 | |
if [ -z $1 ] ; then | |
SQL=" | |
SELECT | |
CONCAT(table_schema, '.', table_name) 'Table', | |
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') 'Tot Size', | |
CONCAT(ROUND(table_rows / 1000000, 2), 'M') 'Rows', | |
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') 'Data', | |
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') 'Idx', | |
ROUND(index_length / data_length, 2) 'Idx Frac' | |
FROM information_schema.TABLES | |
ORDER BY data_length + index_length DESC | |
LIMIT 10; | |
" | |
else | |
SQL=" | |
SELECT | |
CONCAT(table_schema, '.', table_name) 'Table', | |
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') 'Tot Size', | |
CONCAT(ROUND(table_rows / 1000000, 2), 'M') 'Rows', | |
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') 'Data', | |
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') 'Idx', | |
ROUND(index_length / data_length, 2) 'Idx Frac' | |
FROM information_schema.TABLES | |
WHERE table_schema = '$1' | |
ORDER BY data_length + index_length DESC | |
LIMIT 10; | |
" | |
fi | |
mysql -e "$SQL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment