[MySQL] 計算全部資料庫容量 – Count size for all databases

使用情境

總會要計算全部資料庫的總容量吧!竟然沒這SQL語法。


解決方法

下SQL語句直接從Data length計算在群組,以下為個別列出資料庫容量:

SELECT table_schema AS "Database name", SUM( data_length + index_length ) /1024 /1024 /1024 AS  "Size (GB)"
FROM information_schema.TABLES
GROUP BY table_schema

要做加總的話,就Group SUM欄:

GROUP BY "Size (GB)"

Leave a Reply

Your email address will not be published. Required fields are marked *