Created
September 1, 2016 15:26
-
-
Save raynimmo/758947111b5f1ef9cd7dedee24a040cb to your computer and use it in GitHub Desktop.
MySQL queries for displaying allocation/usage of disk space for a database and its tables.
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
| /* View all tables with disk allocation/sizes shown */ | |
| SELECT | |
| table_name, | |
| data_length/1048576,index_length/1048576, | |
| (data_length+index_length)/1048576 as data_used, | |
| data_free/1048576 as data_free, | |
| (data_length+index_length+data_free)/1048576 as disk_used | |
| FROM information_schema.tables where table_schema = 'main' | |
| ORDER BY (data_length+index_length+data_free) ASC; | |
| /* View all tables combined */ | |
| SELECT | |
| SUM(index_length)/1048576 as index_length, | |
| SUM(data_length)/1048576 as data_length, | |
| SUM(data_free)/1048576 as data_free, | |
| SUM(data_length+index_length+data_free)/1048576 as disk_used, | |
| (COUNT(*) * 300 * 1024)/1048576 as overhead, | |
| (SUM(data_length+index_length+data_free) + (COUNT(*) * 300 * 1024))/1048576+150 as estimated_actual_disk_usage | |
| FROM information_schema.tables where table_schema = 'main'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment