查找数据库大小和表大小
Posted 故穿庭树作飞花
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查找数据库大小和表大小相关的知识,希望对你有一定的参考价值。
#查看每个数据库占用的空间 :
SELECT table_schema "Database Name", sum( data_length + index_length ) / 1024 / 1024 "Database Size in MB" FROM information_schema.TABLES GROUP BY table_schema;
#查看数据库下每个表和索引占用的空间:
SELECT table_name AS "Tables",round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = "mysql"
ORDER BY (data_length + index_length) DESC;
#查看排名前10的表 占用的空间:
SELECT CONCAT(table_schema, ‘.‘, table_name),
CONCAT(ROUND(table_rows / 1000000, 2), ‘M‘) table_rows,
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), ‘G‘) data_size,
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), ‘G‘) idx_size,
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), ‘G‘) total_size,
concat(ROUND(index_length / data_length, 2) * 100,"%") idx_data_percent
FROM information_schema.TABLES
ORDER BY data_length + index_length DESC
LIMIT 10;
以上是关于查找数据库大小和表大小的主要内容,如果未能解决你的问题,请参考以下文章