An sql statement in MySQL that queries the size of disk space used by all databases and the size of all tables in a single library

  • 2020-06-01 11:10:36
  • OfStack

Query the SQL statement for how much disk space all databases take up:


select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),' MB') as data_size,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables
group by TABLE_SCHEMA
order by data_length desc;

SQL statement that queries the disk footprint of all tables in a single library:


select TABLE_NAME, concat(truncate(data_length/1024/1024,2),' MB') as data_size,
concat(truncate(index_length/1024/1024,2),' MB') as index_size
from information_schema.tables where TABLE_SCHEMA = 'TestDB'
group by TABLE_NAME
order by data_length desc;

The above statement is valid. Note that the above TestDB is replaced with the database name


Related articles: