Error : Invalid default value for 'datetime'

﹏ヽ暗。殇╰゛Y 2021-11-29 23:14 335阅读 0赞

出现原因由于数据库升到5.7+以后出现了默认值兼容性问题

解决办法:

永久性解决:

修改my.cnf文件

在mysqlId下面加上:

sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

  1. [mysqld]
  2. #
  3. # * Basic Settings
  4. #
  5. user = mysql
  6. pid-file = /var/run/mysqld/mysqld.pid
  7. socket = /var/run/mysqld/mysqld.sock
  8. port = 3306
  9. basedir = /usr
  10. datadir = /var/lib/mysql
  11. tmpdir = /tmp
  12. lc-messages-dir = /usr/share/mysql
  13. skip-external-locking
  14. #
  15. # Instead of skip-networking the default is now to listen only on
  16. # localhost which is more compatible and is not less secure.
  17. bind-address = 127.0.0.1
  18. sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
  19. #
  20. # * Fine Tuning
  21. #
  22. key_buffer_size = 16M
  23. max_allowed_packet = 16M
  24. thread_stack = 192K
  25. thread_cache_size = 8
  26. # This replaces the startup script and checks MyISAM tables if needed
  27. # the first time they are touched
  28. myisam-recover-options = BACKUP
  29. #max_connections = 100
  30. #table_cache = 64
  31. #thread_concurrency = 10
  32. #
  33. # * Query Cache Configuration
  34. #
  35. query_cache_limit = 1M
  36. query_cache_size = 16M
  37. #
  38. # * Logging and Replication

临时性解决:

mysql> set session sql_mode=’ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’;

参考文章:https://blog.csdn.net/chenshun123/article/details/79676567

发表评论

表情:
评论列表 (有 0 条评论,335人围观)

还没有评论,来说两句吧...

相关阅读