set sql_mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
由于数据库的升级,今天在导入从MySQL 5.6导出来的SQL文件时报错:
mysql> source backup.sql
1
ERROR 1067 (42000): Invalid default value for 'CREATE_TIME'
1
因为MySQL 5.6以后timestamp设定默认值规则改变,不能为0000 00-00 00:00:00
解决方法:
查看sql_mode:
mysql> show session variables like '%sql_mode%';
1
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)
修改sql_mode,去掉NO_ZERO_IN_DATE,NO_ZERO_DATE:
mysql> set sql_mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
1
Query OK, 0 rows affected, 1 warning (0.00 sec)
重新执行,成功:
mysql> source cms_user.sql
1
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.03 sec)
---------------------
作者:gong-cy
来源:CSDN
原文:https://blog.csdn.net/gongchenyu/article/details/81298275
版权声明:本文为博主原创文章,转载请附上博文链接!