在这里,我在我的笔记本电脑上的dev DB上按下并运行相同的命令,一遍又一遍;
mysql> select count(*) from tblTraceOutput;
+----------+
| count(*) |
+----------+
| 300175 |
+----------+
1 row in set (0.42 sec)
mysql> select count(*) from tblTraceOutput;
+----------+
| count(*) |
+----------+
| 300175 |
+----------+
1 row in set (0.35 sec)
mysql> select count(*) from tblTraceOutput;
+----------+
| count(*) |
+----------+
| 300175 |
+----------+
1 row in set (0.45 sec)
Run Code Online (Sandbox Code Playgroud)
在这里,我正在做同样的事情,按'向上'并再次运行最后一个命令,但输出是chaning.这里发生了什么?没有什么可以使用这个数据库,因为它是我本地笔记本电脑上的副本,用于我自己的修修补补.为什么表格的行数会发生变化tblTraceOutput?
mysql> SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'smoketrace';
+----------------+------------+
| table_name | table_rows |
+----------------+------------+
| tblCategories | 9 |
| tblResults | 32463 |
| tblRoutes | 300 |
| tblSettings | 2 |
| tblTraceOutput | 303463 |
| tblTraces | 12 |
+----------------+------------+
6 rows in set (0.01 sec)
mysql> SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'smoketrace';
+----------------+------------+
| table_name | table_rows |
+----------------+------------+
| tblCategories | 9 |
| tblResults | 32948 |
| tblRoutes | 246 |
| tblSettings | 2 |
| tblTraceOutput | 297319 |
| tblTraces | 12 |
+----------------+------------+
6 rows in set (0.00 sec)
mysql> SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'smoketrace';
+----------------+------------+
| table_name | table_rows |
+----------------+------------+
| tblCategories | 9 |
| tblResults | 32948 |
| tblRoutes | 451 |
| tblSettings | 2 |
| tblTraceOutput | 302127 |
| tblTraces | 12 |
+----------------+------------+
6 rows in set (0.02 sec)
Run Code Online (Sandbox Code Playgroud)
刷新页面时我在phpMyAdmin中看到了这种行为,所以我想在CLI上查看自己,正如您所看到的,它确实在变化!
mysql --version
./bin/mysql Ver 14.14 Distrib 5.5.8, for Linux (i686) using EditLine wrapper
free -m
total used free shared buffers cached
Mem: 1880 1830 49 0 51 600
-/+ buffers/cache: 1179 701
Swap: 1027 0 1026
uname -a
Linux laptop 3.4.11 #1 SMP Sun Sep 23 15:03:21 BST 2012 i686 i686 i386 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
Mat*_*ode 22
假设您正在使用InnoDB,因为根据MySQL INFORMATION_SCHEMA TABLES文档,这是5.5.x中的默认值.
而且这个说明:
如果表位于INFORMATION_SCHEMA数据库中,则TABLE_ROWS列为NULL.
对于InnoDB表,行计数只是SQL优化中使用的粗略估计.(如果对InnoDB表进行了分区,也是如此.)
如果您使用InnoDB作为存储引擎,则行数是估计值.
For InnoDB tables, the row count is only a rough estimate used in SQL optimization.
Run Code Online (Sandbox Code Playgroud)