Created
April 27, 2016 16:14
-
-
Save Rican7/17303ef990dfd39f692833374f6237d6 to your computer and use it in GitHub Desktop.
Query MySQL database size meta
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
# Get the size meta of every accessible schema | |
SELECT | |
count(*) tables, | |
`table_schema`, | |
format(sum(`table_rows`)/1000000, 3) `rows (M)`, | |
format(sum(`data_length`)/(1024*1024*1024), 3) `data_size (GB)`, | |
format(sum(`index_length`)/(1024*1024*1024), 3) `index_size (GB)`, | |
format((sum(`data_length`+`index_length`))/(1024*1024*1024), 3) `total_size (GB)`, | |
format(sum(`index_length`)/sum(`data_length`), 3) `index_data_ratio` | |
FROM | |
`information_schema`.`TABLES` | |
GROUP BY | |
`table_schema` | |
ORDER BY | |
(sum(`data_length`+`index_length`))/(1024*1024*1024) DESC # Total Size | |
LIMIT 0,1000; | |
# Get the size meta of every table in a schema | |
SELECT | |
`table_schema`, | |
`table_name`, | |
format(`table_rows`/1000, 2) `rows (K)`, | |
format(`data_length`/(1024*1024), 2) `data_size (MB)`, | |
format(`index_length`/(1024*1024), 2) `index_size (MB)`, | |
format((`data_length`+`index_length`)/(1024*1024), 2) `total_size (MB)`, | |
format(`index_length`/`data_length`, 2) `index_data_ratio (MB)` | |
FROM | |
`information_schema`.`tables` | |
WHERE | |
`table_schema` = 'SCHEMA_NAME_HERE' | |
ORDER BY | |
(`data_length`+`index_length`)/(1024*1024) DESC # Total Size | |
LIMIT 0,1000; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to http://blog.kuroichiaki.com/2011/07/mysql-check-table-size-index-size-number-of-rows-and-total-size/ for the very strong starting point on these. 😃