且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取MySQL数据库中所有表的记录计数

更新时间:2023-11-26 23:01:46

SELECT SUM(TABLE_ROWS) 
     FROM INFORMATION_SCHEMA.TABLES 
     WHERE TABLE_SCHEMA = '{your_db}';

文档中的注释:对于InnoDB表中,行数只是SQL优化中使用的粗略估计.您需要使用COUNT(*)进行精确计数(这比较昂贵).

Note from the docs though: For InnoDB tables, the row count is only a rough estimate used in SQL optimization. You'll need to use COUNT(*) for exact counts (which is more expensive).