查询MySQL数据库的总数据大小
SELECT table_schema AS "数据库",
SUM(data_length + index_length) / 1024 / 1024 AS "总大小(MB)"
FROM information_schema.tables
GROUP BY table_schema;
大小单位改成GB
SELECT table_schema AS "数据库",
ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS "总大小(GB)"
FROM information_schema.tables
GROUP BY table_schema;
查询每个表的大小
将your_database_name
替换成你的数据库名称
SELECT
table_name AS "表名",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "大小(MB)"
FROM information_schema.tables
WHERE table_schema = 'your_database_name'
ORDER BY (data_length + index_length) DESC;
查询数据库总数据条数
SELECT SUM(TABLE_ROWS) AS "总数据条数"
FROM information_schema.tables
WHERE TABLE_SCHEMA = 'your_database_name';
查询数据库每个表的数据条数
SELECT
table_name AS "表名",
table_rows AS "数据条数"
FROM information_schema.tables
WHERE table_schema = 'your_database_name'
ORDER BY table_rows DESC;