表结构是这样
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
....省略了一些无关紧要的字段
`CREATE_DATE_` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '创建时间',
....省略了一些无关紧要的字段
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AVG_ROW_LENGTH=579 ROW_FORMAT=DYNAMIC;
MySQL数据库不允许插入零日期,插入零日期会抛出错误。
查看 sql_mode
mysql> show variables like 'sql_mode'; +---------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | Variable_name | Value | +---------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | sql_mode | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION | +---------------+-------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql>
临时修改:
mysql> set session -> sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql>
永久修改:
可以直接修改my.cnf文件
例如: vim /etc/my.cnf
在[mysqld]下面添加如下列:
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
参考:https://www.cnblogs.com/wpjamer/p/7057577.html