10

是否有可用于确定 MySQL 中数据库大小的查询或函数?如果不是,在 MySQL 中查找数据库大小的典型方法是什么?

我在谷歌上搜索,发现SELECT CONCAT(sum(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) / 1024 / 1024),2))," MB") AS Size FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA like '%YOUR_DB_NAME%' ;

它返回一个我知道是 400MB 的数据库474989023196466.25 MB

4

3 回答 3

24

试试这个查询:

SELECT table_schema AS "Data Base Name", 
sum( data_length + index_length ) / 1024 / 1024 AS "Data Base Size in MB" 
FROM information_schema.TABLES GROUP BY table_schema ;

或者有了这个,如果你想 ROUND :

SELECT table_schema AS "Data Base Name", 
ROUND(SUM( data_length + index_length ) / 1024 / 1024, 2) AS "Data Base Size in MB" 
FROM information_schema.TABLES GROUP BY table_schema ;
于 2012-08-07T18:33:56.050 回答
3

尝试:

SELECT table_schema, sum(data_length + index_length) FROM information_schema.TABLES GROUP BY table_schema;
于 2012-08-07T18:34:43.140 回答
0
SELECT table_schema "DB Name", 
       Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" 
FROM   information_schema.tables 
GROUP  BY table_schema; 
于 2016-08-01T10:35:17.817 回答