0%

MySQL 统计每张表的记录数

1
2
3
4
USE information_schema;

# cloud_followup_v2 为要统计的数据库名
SELECT table_name,table_rows FROM TABLES WHERE TABLE_SCHEMA = 'cloud_followup_v2' ORDER BY table_rows DESC;

InnoDB 引擎统计出的table_rows 为大概值。

官方文档解释如下:

1
2
3
4
5
6
7
TABLE_ROWS

The number of rows. Some storage engines, such as MyISAM, store the exact count. For other storage engines, such as InnoDB, this value is an approximation, and may vary from the actual value by as much as 40% to 50%. In such cases, use SELECT COUNT(*) to obtain an accurate count.

TABLE_ROWS is NULL for INFORMATION_SCHEMA tables.

For InnoDB tables, the row count is only a rough estimate used in SQL optimization. (This is also true if the InnoDB table is partitioned.)

行数。一些存储引擎(例如 MyISAM)存储准确的计数。对于其他存储引擎,例如InnoDB,该值是一个近似值,可能与实际值相差40%至50%。在这种情况下,请使用SELECT COUNT(*)以获得准确的计数。

TABLE_ROWSNULLINFORMATION_SCHEMA表。

对于InnoDB表,行数只是SQL优化中使用的粗略估计。(如果InnoDB表已分区,则也是如此。)