前言
在开发中我们想知道某个数据库,或者某个数据表的内存大小,那么怎么查询呢?下面通过简单示例一一介绍,希望对您有所帮助。
某表每行所占字节数
SELECT
TABLE_NAME ,
CONCAT((DATA_LENGTH + INDEX_LENGTH), ' 字节') AS '每行占用字节数'
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = '你的数据库名'
AND
TABLE_TYPE = 'BASE TABLE';
某个数据库各表所占内存大小
SELECT
table_schema AS "数据库",
table_name AS "表名",
table_rows AS "记录数",
TRUNCATE ( data_length / 1024 / 1024, 2 ) / 1024 AS "数据容量(GB)",
TRUNCATE ( index_length / 1024 / 1024, 2 ) / 1024 AS "索引容量(GB)"
FROM
information_schema.TABLES
WHERE
table_schema = '你的数据库名称'
ORDER BY
data_length DESC,
index_length DESC;