Navicat: The number of rows is not 0 after truncating the table or emptying the table

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.
insert image description here


2 reasons

information_schemaMySQL TABLESstores 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_ROWSfield records the number of rows of data in the table.
insert image description here
It can be seen from TABLESthe table that after the data table is truncated or emptied, the fields TABLESin the table TABLE_ROWSwill not be updated.

Why is it inconsistent with the actual number of rows?

The official MySQL documentation TABLE_ROWSexplains 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(*)

Guess you like

Origin blog.csdn.net/weixin_46098577/article/details/127753087