查看库大小
例如:查看当前MySQL中数据总量超过2GB的库:
select table_schema as '数据库',table_rows as '记录数',data_size as '数据容量(GB)',index_size as '索引容量(MB)'
from (selecttable_schema,sum(table_rows) as 'table_rows',sum(truncate(data_length/1024/1024/1024, 1)) as 'data_size',sum(truncate(index_length/1024/1024, 1)) as 'index_size'from information_schema.tablesgroup by table_schema
) as t
where data_size > 2
order by data_size desc, index_size desc
执行结果:
查看表大小
例如:查看数据总量超过300MB的数据库表:
select CONCAT(table_schema,".",table_name) as '数据库表',table_rows as '记录数',data_size as '数据容量(MB)',index_size as '索引容量(MB)'
from (selecttable_schema, table_name, table_rows,truncate(data_length/1024/1024, 1) as 'data_size',truncate(index_length/1024/1024, 1) as 'index_size'from information_schema.tables
) as t
where data_size > 300
order by data_size desc, index_size desc
执行结果: