将MySql的数据从5.6导入到5.7时,若时间的默认值为零会报错Error : Invalid default value for ‘comment_date’。

产生这个报错的原因:

NO_ZERO_DATE:在非严格模式下,可以插入形如“0000-00-00 00:00:00”的非法日期,MySQL数据库仅抛出一个警告。而启用该选项后,MySQL数据库不允许插入零日期,插入零日期会抛出错误而非警告。

解决方法如下:

mysql -u root -p //登陆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;

重新创建数据库,导入数据即可。

转载来源:点击这里

Last modification:May 18th, 2020 at 05:55 pm
如果觉得我的文章对你有用,请随意赞赏