mysql5.7.21导入5.6的数据报Error : Invalid default value for ‘comment_date’

精选文章 2018年2月11日 6.99K

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

产生这个报错的原因:

NO_ZERO_DATE:在非严格模式下,可以插入形如“2014-07-17 23:29: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;

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


关注微信公众号『PHP学习网

第一时间了解最新网络动态
关注博主不迷路~

PHP学习网:站内收集的部分资源来源于网络,若侵犯了您的合法权益,请联系我们删除!
分享到:
赞(0)

文章评论

您需要之后才可以评论
0点赞 0评论 收藏 QQ分享 微博分享

PHP学习网

PHP学习网