简体   繁体   English

相同的 MySQL 数据库导入显示不同数量的记录

[英]Same MySQL database import showing different numbers of records

Same database imported 3 three times after empty the entire database and surprisingly every time it shows different number of records.在清空整个数据库后,同一数据库导入了 3 次,令人惊讶的是每次都显示不同数量的记录。 Why?为什么?

1st time import:第一次导入: 在此处输入图片说明

2nd time import:第二次导入: 在此处输入图片说明

3rd time import:第三次导入: 在此处输入图片说明

It is not right to trust on Rows count as shown in picture it show approxmiate value as error suggested.如图所示信任行数是不对的,它显示了错误建议的近似值。 So the question is how can we ensure that database is right and no record missing?那么问题来了,我们如何确保数据库是正确的,并且没有丢失记录? note: short-cut require can't use count with each table it will lots of time.注意:快捷方式要求不能对每个表使用计数,它会花费很多时间。

MySQL is, surprisingly, really bad at numbers.令人惊讶的是,MySQL 在数字方面非常糟糕。 For InnoDB tables those are often estimates of how many rows it contains and they can be wildly wrong.对于 InnoDB 表,这些通常是对它包含多少行的估计,它们可能是非常错误的。

The way it computes the numbers you're seeing is by taking the total size of the table data and dividing by the average row size in bytes.它计算您看到的数字的方法是将表数据的总大小除以平均行大小(以字节为单位)。 This is usually a good enough approximation of your data, but it can be very misleading, off by a factor of up to 100.这通常是您数据的足够近似值,但它可能会非常具有误导性,最多可达 100 倍。

The only way to know for sure is to do COUNT(*) , something that can take some time to compute on a very active table.确定知道的唯一方法是执行COUNT(*) ,这可能需要一些时间在非常活跃的表上进行计算。

Tools like phpmyadmin/adminer always picks the row count from INFORMATION_SCHEMA.像 phpmyadmin/adminer 这样的工具总是从 INFORMATION_SCHEMA 中选择行数。 In case of InnoDb storage engine the row count is a rough estimate, it is never the exact value.在 InnoDb 存储引擎的情况下,行数是一个粗略的估计,它永远不是准确的值。 The table_rows which phpmyadmin picks which is never accurate for Innodb phpmyadmin 选择的table_rows对于 Innodb 来说永远不准确

SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'table_name';

For exact value we need对于我们需要的确切值

SELECT count(*) FROM 'table_name';

For reference: http://dev.mysql.com/doc/refman/5.7/en/tables-table.html供参考: http : //dev.mysql.com/doc/refman/5.7/en/tables-table.html

You'll notice that all of the "negative mysql records" This isn't a negative sign its ~, which means approximately.你会注意到所有的“负面 mysql 记录”这不是一个负号它的 ~,这意味着大约。 if you want actual count use如果你想要实际计数使用

SELECT count(*) FROM 'table_name';

I wouldn't rely on comparison of numbers with a tilde (~) as prefix.~ means approximation.我不会依赖以波浪号 (~) 作为前缀的数字比较。~ 表示近似值。

Based on bencoder response to this phpMyAdmin - What a tilde (~) means in rows column?基于 Bencoder 对此phpMyAdmin 的响应- 行列中的波浪号 (~) 是什么意思? the approximation can vary a lot.近似值可能会有很大差异。

To check the real number of rows imported use: select count(*) from TABLE_NAME要检查导入的实际行数,请使用: select count(*) from TABLE_NAME

The number you are seeing is approximation.您看到的数字是近似值。 To get the actual number JUST CLICK ON THE NUMBER.要获得实际数字,只需单击数字即可。 You will see the actual number.您将看到实际数字。 You do not need to run any query to view actual row number.您无需运行任何查询即可查看实际行号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM