mysql 配置 explicit_defaults_for_timestamp
在之前的配置中,除了目录之外,唯独添加了这一项配置,为什么?
因为mysql中timestamp类型和其他的类型不一样;
在之前先了解一下current timestamp和on update current timestamp:
a.current timestamp :当insert时,如果timestamp列属性设为current_timestamp,那么该列会被强制写入当前的系统时间(无论你是不是设置了默认值);
b.on update current timestamp:当update时,如果字段属性设为on update current_timestamp,那么该列会被强制写入当前系统时间(无论是否要更新该列);
官方解释如下:
1. 在默认情况下(explicit_defaults_for_timestamp=1),如果timestamp数据列没有明确设置null属性,那么该列会被自动添加not null属性,如果写入数据时设置null,那么mysql会自动把当前时间戳写入该列,作为默认值 ...
注:其他类型的列,在没有明确设置not null的情况下,默认是允许null值;
2. 表中如果有多个timestamp列,那么第一列如果没有指定null或者设置默认值,也没有指定on update语句,那么该列会被自动添加default current_timestamp和on update current_timestamp属性;
3.同第2条,除了第一列之外,其他的timestamp列如果没有指定null属性,也没有指定默认值,那么该列会被自动添加default '0000-00-00 00:00:00'属性;如果insert语句没有为该列添加指定值,那么该列会被插入'0000-00-00 00:00:00',而且不会提示警告;
所以我们在my.ini配置文件中,添加了该项配置,否则启动时,会提示以下报警:
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
更多相关文章
- Java向MySQL数据库插入时间类型Date数据时需要注意的问题
- MySQL入门很简单: 2 MySQL数据类型
- Mysql 修改字段类型
- Ms sql 2005 中的bit 数据类型
- SQLServer---查询过程中的数据类型转化
- PostgreSQL: array 数组类型添加元素 数组的使用
- Recordset记录集对象的属性
- 要在更新属性上执行的TRIGGER?
- 原因及解决:java.sql.SQLException: 无效的列类型: 1111