Table size

from the Artful Common Queries page


This info is often needed, so put it in a stored procedure ...
use system;
drop procedure if exists tsiz;
create procedure tsiz( db varchar(64), tbl varchar(64) )
select  
  concat(round(sum(table_rows)/1000000,2),'m') rows, 
  concat(round(sum(data_length)/(1024*1024*1024),2),'g') data, 
  concat(round(sum(index_length)/(1024*1024*1024),2),'g') idx, 
  concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'g') total_size, 
  round(sum(index_length)/sum(data_length+index_length),2) idxfrac 
from information_schema.tables 
where table_schema=db and table_name=tbl;

Last updated 23 May 2017