#查看每个数据库所占磁盘大小
SELECT TABLE_SCHEMA AS "库名", TRUNCATE(SUM(`DATA_LENGTH`) / 1024 / 1024, 2) AS "表所占空间(MB)", TRUNCATE(SUM(`INDEX_LENGTH`) / 1024 / 1024, 2) AS "索引所占空间(MB)", TRUNCATE((SUM(`DATA_LENGTH`) + SUM(`INDEX_LENGTH`)) / 1024 / 1024,2) AS "空间累计(MB)"FROM information_schema.`TABLES`GROUP BY `TABLE_SCHEMA`;
#查看某个数据库各表所占磁盘大小
SELECT TABLE_NAME, TRUNCATE (DATA_LENGTH / 1024 / 1024, 2) AS "DATA_SIZE(MB)", TRUNCATE (INDEX_LENGTH / 1024 / 1024, 2) AS "INDEX_SIZE(MB)"FROM INFORMATION_SCHEMA. TABLESWHERE TABLE_SCHEMA = 'db_name'GROUP BY TABLE_NAMEORDER BY DATA_LENGTH DESC;