查找数据库大小和表大小

#查看每个数据库占用的空间 :
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;

posted @ 2018-04-17 18:02  故穿庭树作飞花  阅读(116)  评论(0编辑  收藏  举报