我对MySQL中的行数感到困惑。 phpMyAdmin和count查询返回的总行数不同。
我的表结构是InnoDB
。
Showing rows 0 - 24 (655537 total, Query took 0.1527 seconds.)
这是浏览表时的结果。
我的计数查询是
SELECT count(*) FROM `table_name`
这将返回为602030
答案 0 :(得分:2)
When you browse using a tool, like phpmyadmin or heidiSQL, a query like this is executed:
SHOW TABLE STATUS LIKE 'table';
this value is inaccurate and if you run it many times, it always gives different results.
on the contrary the query:
select count(*) from table
is actually counting the records, and gives a correct result.
As mentioned in mysql documentation https://dev.mysql.com/doc/refman/8.0/en/show-table-status.html中的字符串:
一些存储引擎(例如MyISAM)存储 精确计数。对于其他存储引擎,例如InnoDB,此值为 近似值,可能与实际值相差40% 到50%在这种情况下,请使用SELECT COUNT(*)获得准确的 计数。
答案 1 :(得分:0)
MySQL说:通过INNODb,总数仅是计数的近似值。
https://dev.mysql.com/doc/refman/8.0/en/show-table-status.html