1、分数据库查询数据量(使用时把database_name换成需要查询的数据库名称)
SELECT table_schema "Database Name",
SUM(data_length + index_length) / 1024 / 1024 "Database Size in MB"
FROM information_schema.tables
WHERE table_schema = 'database_name';
2、按连接查询连接下所有数据库的数据量
SELECT
IFNULL(table_schema, 'Total') AS "Database Name",
SUM(data_length + index_length) / 1024 / 1024 / 1024 AS "Size in GB"
FROM
information_schema.tables
GROUP BY
table_schema WITH ROLLUP;
3、按数据表查询表的数据量
SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS '数据量(MB)'
FROM information_schema.tables
WHERE table_schema = '你的数据库名' AND table_name = '你的表名';