mysql update_time

11 篇文章 0 订阅

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 |
+---------------+

版本相差甚远,但是由此看来 线上可以通过此条件来判断。这是非常重要的一点。

get last update of database return null (mysql)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值