在之前的配置中,除了目录之外,唯独添加了这一项配置,为什么?
因为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).
那么添加了该项配置(explicit_defaults_for_timestamp=1)之后有什么效果呢?
1. 如果timestamp列没有显示指定not null属性,那么默认允许null,当插入数据时,不会被写入currrent timestamp;
2. mysql不会自动给第一个timestamp列添加default current_timestamp和on update current_timestamp属性(除非你在建表时显示指明);
3. 如果timestamp列指明是not null属性,而且没有指定默认值,这时候写入数据时如果不给该列写入数据,那么有以下两种情况:
a. 指定strict sql_mode的情况下,会直接报错;
b. 未指定strict sql_mode的情况下,会默认插入'0000-00-00 00:00:00',并发生一个报警;