mysql update_time
在 mysql中有一个DB 是 information_schema。顾名思义就是一些schema 的信息,表的结构,字段,占用大小等等信息都在其中。今天使用到的是其中的table表。
information_schema tables
如下是所有的字段的含义
字段 | 含义 |
---|---|
Table_catalog | 数据表登记目录 |
Table_schema | 数据表所属的数据库名 |
Table_name | 表名称 |
Table_type | 表类型[system view |
Engine | 使用的数据库引擎[MyISAM |
Version | 版本,默认值10 |
Row_format | 行格式[Compact |
Table_rows | 表里所存多少行数据 |
Avg_row_length | 平均行长度 |
Data_length | 数据长度 |
Max_data_length | 最大数据长度 |
Index_length | 索引长度 |
Data_free | 空间碎片 |
Auto_increment | 做自增主键的自动增量当前值 |
Create_time | 表的创建时间 |
Update_time | 表的更新时间 |
Check_time | 表的检查时间 |
Table_collation | 表的字符校验编码集 |
Checksum | 校验和 |
Create_options | 创建选项 |
Table_comment | 表的注释、备注 |
如果需要知道一个表什么时候有更新只需要关注update_time 即可。
InnoDB update_time NULL
通过实际测试中发现test环境的update_time 一直是null,这就没有办法通过udpate_time 来进行判断了。那么为什么会出现这个问题?在网上查找了相关资料,发现其他人也碰到了相同的问题,结论是 InnoDB不支持,而MyISAM 支持。建议换引擎。这不是扯淡吗。。为了update_time 换引擎,这不是因噎废食吗?并且在线上的DB 是可以显示的。还是看看 stackoverflow 找找资料。最终找到了一下解析:
As MySQL documentation on information_schema.tables says (emphasis added):
Beginning with MySQL 5.7.2, UPDATE_TIME displays a timestamp value for the last UPDATE, INSERT, or DELETE performed on InnoDB tables that are not partitioned. Previously, UPDATE_TIME displayed a NULL value for InnoDB tables. For MVCC, the timestamp value reflects the COMMIT time, which is considered the last update time. Timestamps are not persisted when the server is restarted or when the table is evicted from the InnoDB data dictionary cache.
The UPDATE_TIME column also shows this information for partitioned InnoDB tables in MySQL 5.7.8 and later. Previously this column was always NULL for such tables. (Bug #17299181, Bug #69990)
Probably you are using innodb tables and your MySQL version is earlier than described in the documentation.
简单的是在mysql 版本5.7.8 之前InnoDB 确实不支持。但是在之后的版本是可以支持的。于是查看了两者的版本:
test env:
5.5.52-38.3-log
live env:
+---------------+
| version() |
+---------------+
| 5.7.21-20-log |
+---------------+
版本相差甚远,但是由此看来 线上可以通过此条件来判断。这是非常重要的一点。