Article directory
1 Problem description
The following data tables have been truncated or cleared, but the row count column still shows the number of rows before truncated or cleared.
2 reasons
information_schema
MySQL TABLES
stores the information of all tables in all databases under the current connection in the table in the database under the current connection, and the TABLE_ROWS
field records the number of rows of data in the table.
It can be seen from TABLES
the table that after the data table is truncated or emptied, the fields TABLES
in the table TABLE_ROWS
will not be updated.
Why is it inconsistent with the actual number of rows?
The official MySQL documentation TABLE_ROWS
explains the field as follows:
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.
The number of rows. Some storage engines (like MyISAM) store the exact count. For other storage engines, such as InnoDB, this value is an approximation and may vary by 40% to 50% from the actual value. In this case, use SELECT COUNT( ) to get an accurate count.
So, don't be confused by the number of rows given by MySQL. To get the real number of rows in a table, you have to beSELECT COUNT(*)