mysql - MySQL显示总计和计数查询中的行数不同

标签 mysql phpmyadmin

我对 MySQL 中的行数感到困惑。 phpMyAdmin 和 count 查询返回的总行数不同。

我的表结构是InnoDB .

Showing rows 0 - 24 (655537 total, Query took 0.1527 seconds.)

这是浏览表格时的结果。

我的计数查询是

SELECT count(*) FROM `table_name`

这将返回为 602030

enter image description here

最佳答案

当您使用 phpmyadmin 或 heidiSQL 等工具浏览时,会执行如下查询:

SHOW TABLE STATUS LIKE 'table';

这个值不准确,如果运行多次,它总是会给出不同的结果。

相反的查询:

select count(*) from table

实际上正在计算记录,并给出正确的结果。

正如mysql文档中提到的https://dev.mysql.com/doc/refman/8.0/en/show-table-status.html :

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.

关于mysql - MySQL显示总计和计数查询中的行数不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53396668/

相关文章:

java - hibernate + Mysql : Data truncation: Incorrect datetime value

php - SQL 在 phpMyAdmin 中有效,但在 php 中无效

mysql - 如果字符串以指定字符开头或结尾,则替换字符串中的字符

MySQL 错误 1036 : table is read only

php - mysql搜索标题、描述和多行标签(关于条件)

mysql - 存储的 MySQL 查询中的 Where 子句问题

php - 使用 PHP 预选 MySQL 填充的下拉列表

mysql - 检查 select 语句是否返回带有 IF 的内容

mysql - mysql 数据库访问被拒绝

PHP mysql自动递增将BLANK传递给数据库