威言威语
我愿像茶,苦涩留心,清香予人。
威言威语
当前位置: 首页 > 网络 > 正文

导入数据库时报错1067 – Invalid default value for 'comment_date'

之前将mysql的数据版本从5.6升级到了5.7,导入备份的数据库的时候,若时间的默认值为零会报错Error : Invalid default value for ‘comment_date’。主要原因是mysql升级到5.7而引起的默认值不兼容的问题。
导入数据库时报错1067 – Invalid default value for 'comment_date'

之前将mysql的数据版本从5.6升级到了5.7,导入备份的数据库的时候,若时间的默认值为零会报错Error : Invalid default value for 'comment_date'。后来有从5.7升级到了8.0,同样有这个问题。

做了记录以备之后遇到。

5.6->5.7


root@localhost:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14624
Server version: 5.7.30-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2020, 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.00 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye
root@localhost:~#

5.7->8.0 服务器系统是Debian,同时使用了Docker。


root@localhost:~# docker exec -it db mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 471
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'
    -> ;
Query OK, 0 rows affected, 1 warning (0.06 sec)

mysql> exit;
Bye
root@localhost:~#

完成之后再重建数据库,就能导入了。

您可能还会对这些文章感兴趣!

导入数据库时报错1067 – Invalid default value for 'comment_date':目前有 10 条评论

  1. 简单生活
    6楼
    简单生活:Google Chrome 78.0.3904.108 Windows 10

    好久没更新了!

    2020-03-29 18:36 回复
  2. 吹梦到西洲
    5楼
    吹梦到西洲:Firefox 74.0 Mac OS X  10.15

    技术流阿

    2020-03-20 13:11 回复
  3. 夏日博客
    4楼
    夏日博客:Google Chrome 63.0.3239.132 Windows 7

    是时候该更新了。 :oops:

    2019-12-24 17:48 回复
  4. Lvtu
    地板
    LvtuSafari 12.0.2 Mac OS X  10.14.2

    难得更新一篇呀。。。。

    2019-01-14 12:00 回复
  5. 林三
    板凳
    林三Google Chrome 71.0.3578.98 Windows 7

    过来看看有没有新东西学习!

    2018-12-13 16:00 回复
  6. 陈大猫
    沙发

    居然更新了。。。看来还没有放弃。

    2018-11-23 11:33 回复

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

gravatar

question razz sad smile redface biggrin eek shock confused cool lol mad rolleyes wink cry