下面会用到information_schema的tables来进行统计,首先进入
use information_schema;查看data_length : 记录表的大小(单位字节)
select concat(round(sum(data_length/1024*1024*1024),2),'G') as data from tables;查看表的大小,按指定的库名和表名
select concat(round(sum(DATA_LENGTH/1024*1024*1024),2),'G') as data from TABLES where table_schema='库名' and table_name='表名';查看指定的数据库大小
select concat(round(sum(DATA_LENGTH/1024*1024*1024),2),'G') as data from TABLES where table_schema='库名';查看所有表大小并排序
SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows/1000000,4),'M') AS 'Number of Rows', CONCAT(ROUND(data_length/(1024*1024*1024),4),'G') AS 'Data Size',CONCAT(ROUND(index_length/(1024*1024*1024),4),'G') AS 'Index Size', CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),4),'G') AS'Total'FROM information_schema.TABLES ORDER BY --total DESC;