查看database大小
如下命令会显示各Database大小(以MB计算)。
SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema
结果如下:
| Database | Size (MB) |
+--------------------+--------------+
| http_certs | 941.79687500 |
| information_schema | 0.15625000 |
| mysql | 2.39560223 |
| performance_schema | 0.00000000 |
| sys | 0.01562500 |
+--------------------+--------------+
查看某个特定table大小
将下面命令中的$DB_NAME
和$TABLE_NAME
替换为要查询的database和table名即可。
SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
WHERE table_schema = "$DB_NAME"
AND table_name = "$TABLE_NAME";
查看全部table的大小
下面的命令由大到小列出每一个数据库中每一个表的大小。
SELECT
table_schema as `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC;