如果未启用每个文件的 innodb,如何在 mysql 5.6 中查找 innodb 表的数据长度和索引长度

How to find data length and index length of innodb tables in mysql 5.6 if innodb per file is not enabled

在 mysql 5.6 中,我们禁用了每个文件的 innodb。我只想知道表数据和索引的大小。请让我知道如何获得准确的数据。

如果启用 innodb_file_per_table,则获取数据长度和索引长度的方式相同:

SELECT data_length, index_length
FROM INFORMATION_SCHEMA.TABLES
WHERE ENGINE='InnoDB';

或者如果你想要总数:

SELECT SUM(data_length+index_length) AS total
FROM INFORMATION_SCHEMA.TABLES
WHERE ENGINE='InnoDB';

如果你 enable/disable innodb_file_per_table.

数据长度和索引长度没有区别

不同的是data_free。如果您禁用了 innodb_file_per_table,将针对 INFORMATION_SCHEMA.TABLES 中的每一行报告整个表空间的 data_free。所以你不应该 SUM() 而 data_free,因为那会给你一个误导性的结果。它会多次计数相同data_free,等于表空间中InnoDB表的数量。

SHOW TABLE STATUS 提供当前数据库的信息。请注意,Data_free 将引用 ibdata1,而不是 table。