gpt4 book ai didi

MySQL - 我没有看到数据,但 mysql 说,有行

转载 作者:行者123 更新时间:2023-11-29 05:54:12 24 4
gpt4 key购买 nike

我有表 ip_per_nat_vlan,innodb 格式。当我给 truncate table 时,表是空的。

然后我有 php 脚本,它将数据填充到这个表中。

这个脚本什么时候完成没有错误(简单的插入状态)情况如下:

select * from ip_per_nat_vlan;

Empty set (0.00 sec)

.

select count(*) from ip_per_nat_vlan;

+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)

.

show table status;

+----------------------------------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+------------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+----------------------------------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+------------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| ip_per_nat_vlan | InnoDB | 10 | Dynamic | 141291 | 100 | 14172160 | 0 | 6832128 | 25165824 | 143563 | 2017-12-24 16:26:40 | 2018-06-13 09:01:33 | NULL | utf8_unicode_ci | NULL |

MySQL 说,应该有 14172160 行,但我没有看到。哪里可能有问题?交易?但是我没有看到任何正在运行的线程,也没有任何错误。

谢谢。

表的结构是:

+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| ipAddress | varchar(255) | NO | UNI | NULL | |
| nat | int(11) | NO | | NULL | |
| vlan | int(11) | NO | | NULL | |
| district | varchar(255) | YES | | NULL | |
| idOblasti | int(11) | YES | | NULL | |
| type | varchar(255) | NO | | NULL | |
| macAddress | varchar(255) | NO | | NULL | |
+------------+--------------+------+-----+---------+----------------+

最佳答案

有多种方法可以“计算”表格中的行。

正常方式。数一数。

select count(*) as table_rows from table_name ; 

准确性:运行查询时 100% 准确计数。

使用 information_schema 表

select  table_rows
from information_schema.tables
where table_schema = 'database_name'
and table_name = 'table_name' ;

准确度:只是一个近似值。如果表是频繁插入和删除的目标,则结果可能与实际计数相差甚远。这可以通过更频繁地运行 ANALYZE TABLE 来改善。效率:很好,完全不碰 table 。

由于计数选项是 100% 准确的,因此您的表不包含任何数据。检查您的代码和 MySQL 的默认提交选项。

看起来您正在插入行,但没有提交它们,请检查您的索引长度。

在这里查看更多详细信息

https://dba.stackexchange.com/questions/151769/mysql-difference-between-using-count-and-information-schema-tables-for-coun

关于MySQL - 我没有看到数据,但 mysql 说,有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51260431/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com