
Get table sizes from a database
If you need to check whether a table size changed after a process or just to monitor the table sizes of any database, the following query will help you:
Sizes in MB:
1 |
SELECT table_name AS `Table`, round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` FROM information_schema.TABLES WHERE table_schema = "your-database-name" |
Sizes in Bytes:
1 |
SELECT table_name AS `Table`, round(((data_length + index_length) ), 2) `Size in Bytes` FROM information_schema.TABLES WHERE table_schema = "your-database-name" |
In addition, if you want to do it from CLI and get an exported file, you can do the following from your terminal:
1 |
mysql -uuser -ppassword your-database-name -e'SELECT table_name AS `Table`, round(((data_length + index_length) ), 2) `Size in Bytes` FROM information_schema.TABLES WHERE table_schema = "your-database-name"' > your_report.csv |