I'm currently migrating from SQL Server to MySQL. When i try to match the number of rows i query information_Schema.tables. I noticed that there are some differences between the migrated information and the source information.
However, I did a select count(*) from table;
gave me the correct number of rows
Why is there a difference between the information_Schema.tables.table_rows
and the select count(*) from table
?
Best Answer
The root cause is the storage engine. InnoDB does not update the
information_schema.tables.table_rows
column.I have old posts that explain this further
Apr 23, 2012
: Why is a secondary index chosen over a clustered index for SELECT COUNT(*) ...?May 16, 2012
: Why doesn't InnoDB store the row count?Mar 03, 2014
: The most efficient method to obtain the total entries into a mysql tableYou can get an approximation using
SHOW INDEXES FROM
against the tableIf you would like to count all the tables in your current database regardless of the storage engine, just run this:
GIVE IT A TRY !!!