Get record counts for all tables in MySQL database

Mark picture Mark · Nov 13, 2008 · Viewed 330.4k times · Source

Is there a way to get the count of rows in all tables in a MySQL database without running a SELECT count() on each table?

Answer

Hates_ picture Hates_ · Nov 13, 2008
SELECT SUM(TABLE_ROWS) 
     FROM INFORMATION_SCHEMA.TABLES 
     WHERE TABLE_SCHEMA = '{your_db}';

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).