SELECT
table_schema,
sum (data_length + index_length) / 1024 / 1024 as MB
FROM
information_schema.tables
GROUP BY
table_schema
ORDER BY
sum (data_length + index_length) desc;
mysql> SELECT table_schema, sum(data_length+index_length) /1024 /1024 as MB FROM information_schema.tables GROUP BY table_schema ORDER BY sum(data_length+index_length) desc;
+--------------------+---------------+
| table_schema | MB |
+--------------------+---------------+
| weather | 3599.71875000 |
| information_schema | 0.00878906 |
+--------------------+---------------+
2 rows in set (8.41 sec)
GB単位
SELECT
table_schema,
sum (data_length + index_length) / 1024 / 1024 / 1024 as GB
FROM
information_schema.tables
GROUP BY
table_schema
ORDER BY
sum (data_length + index_length) desc;
mysql> SELECT table_schema, sum(data_length+index_length) /1024 /1024/1024 as GB FROM information_schema.tables GROUP BY table_schema ORDER BY sum(data_length+index_length) desc;
+--------------------+----------------+
| table_schema | GB |
+--------------------+----------------+
| weather | 3.515350341797 |
| information_schema | 0.000008583069 |
+--------------------+----------------+
2 rows in set (3.40 sec)
特定のデータベースのサイズを確認する
SELECT
table_name,
engine,
table_rows as tbl_rows,
avg_row_length as rlen,
floor ((data_length + index_length) / 1024 / 1024) as allMB_総容量,
floor ((data_length) / 1024 / 1024) as dMB_データ容量,
floor ((index_length) / 1024 / 1024) as iMB_インデックス容量
FROM
information_schema.tables
WHERE
table_schema = database()
ORDER BY
(data_length + index_length) desc;