将MysqL的数据从5.6导入到5.7时,若时间的默认值为零会报错Error : Invalid default value for ‘comment_date’。
产生这个报错的原因:
NO_ZERO_DATE:在非严格模式下,可以插入形如“2014-07-17 23:29:00”的非法日期,MysqL数据库仅抛出一个警告。而启用该选项后,MysqL数据库不允许插入零日期,插入零日期会抛出错误而非警告。
解决方法如下:
Enter password:
Welcome to the MysqL monitor. Commands end with ; or g.
Your MysqL connection id is 26
Server version: 5.7.21 Homebrew
copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered Trademark of Oracle Corporation and/or its
affiliates. Other names may be Trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MysqL> set global 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.01 sec)
MysqL> commit;
Query OK, 0 rows affected (0.00 sec)
MysqL> exit;
重新创建数据库,导入数据即可。