插入的表中其中有一个字段信息:`end_time` datetime not null default '0000-00-00 00:00:00' comment 'end time',明显想要插入年月日未0的值。
mysql中查询:select @@sql_mode或者select @@global.sql_mode查询出数据库严格模式的相关信息。mysql在5.7之后默认使用严格模式。
mysql> select @@sql_mode -> ; +-----------------------------------------------------------------------------------------------------------------------+ | @@sql_mode | +-----------------------------------------------------------------------------------------------------------------------+ | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION | +-----------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> select @@global.sql_mode; +-----------------------------------------------------------------------------------------------------------------------+ | @@global.sql_mode | +-----------------------------------------------------------------------------------------------------------------------+ | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION | +-----------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
可以看出有这两个属性:NO_ZERO_IN_DATE,NO_ZERO_DATE
NO_ZERO_DATE影响月日为0的插入,NO_ZERO_IN_DATE影响年月日为0的插入,会影响到DATE、DATETIME、TIMESTAMP三种字段类型中对日期部分为0的处理。
####设置当前当前会话去掉NO_ZERO_IN_DATE,NO_ZERO_DATE
mysql>set session sql_mode = "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION";
再次插入表成功。