您的位置:首页 > 博客中心 > 数据库 >

查找数据库大小和表大小

时间:2022-03-15 07:37

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

热门排行

今日推荐

热门手游