这种报错多是你 MySQL 升级到 5.7 而引起的默认值不兼容的问题。看看你的字段名是什么,我的是时间字段,类型是 datetime。想到可能是类型的默认值被限制了,查看 sql_mode。果然:NO_ZERO_IN_DATE,NO_ZERO_DATE 这两个参数限制时间不能为0

查看 sql_mode

show variables like '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.01 sec)

临时修改:

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)

永久修改:

可以直接修改 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

发表评论

Close Menu