1. 程式人生 > >查找數據庫大小和表大小

查找數據庫大小和表大小

SQ per form info mysql desc 查看數據庫 for limit

#查看每個數據庫占用的空間 :
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;

查找數據庫大小和表大小