mysql のコマンドで、テーブルの定義や細かいステータスは見れますが、ふと収容先の全データベースのサイズを見る必要があったので、自作してます。
名前は、コマンド用なので短くして、引数なしにしてます。
[ DDL ]
CREATE DEFINER=`root`@`localhost` PROCEDURE `dbsize`()
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT '簡単データベースサイズ'
BEGIN
SELECT
table_schema,
sum(data_length) /1024/1024 + sum(index_length) /1024/1024 AS total_mb,
sum(data_length) /1024/1024 AS data_mb,
sum(index_length) /1024/1024 AS index_mb
FROM
information_schema.tables
GROUP BY
table_schema
ORDER BY
sum(data_length + index_length) DESC;
END
[ 利用例 ]
mysql> call dbsize; +--------------------+---------------+---------------+---------------+ | table_schema | total_mb | data_mb | index_mb | +--------------------+---------------+---------------+---------------+ | ?????????? | 4028.40940857 | 2589.96604919 | 1438.44335938 | | ?????????? | 3389.75976753 | 2149.07226753 | 1240.68750000 | | ?????????? | 1720.67187500 | 812.59375000 | 908.07812500 | | mysql | 11.26994324 | 10.99552917 | 0.27441406 | | ?????? | 3.45312500 | 2.07812500 | 1.37500000 | | information_schema | 0.15625000 | 0.15625000 | 0.00000000 | | sys | 0.01562500 | 0.01562500 | 0.00000000 | | performance_schema | 0.00000000 | 0.00000000 | 0.00000000 | +--------------------+---------------+---------------+---------------+ 19 rows in set (0.27 sec) Query OK, 0 rows affected (0.27 sec)