tags:

views:

3538

answers:

2

Heya

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?

Cheers

+6  A: 

You can probably put something together with Tables table. I've never done it, but it looks like it has a column for *TABLE_ROWS* and one for TABLE NAME.

To get rows per table, you can use a query like this:

SELECT table_name, table_rows
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '**YOUR SCHEMA**';
gpojd
Thanks that works too.
Mark
+7  A: 
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.

Hates_
or, if you want for each table:SELECT table_name, TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{your_db}';
TheSoftwareJedi