11/09/2016

[ MySQL ] How to grab database and table size.




1. Grab all database size.

SELECT table_schema, SUM(data_length + index_length)/1024/1024 AS total_mb, SUM(data_length)/1024/1024 AS data_mb, SUM(index_length)/1024/1024 AS index_mb, COUNT(*) AS tables, CURDATE() AS today FROM information_schema.tables GROUP BY table_schema ORDER BY 2 DESC;


2. Grab all table size.

SELECT table_schema, table_name, (data_length + index_length)/1024/1024 AS total_mb, (data_length)/1024/1024 AS data_mb, (index_length)/1024/1024 AS index_mb, CURDATE() AS today FROM information_schema.tables ORDER BY 3 DESC;