MySQL Incorrect datetime value: '0000-00-00 00:00:00'

后端 未结 19 1012
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 15:51

I\'ve recently taken over an old project that was created 10 years ago. It uses MySQL 5.1.

Among other things, I need to change the default character set from latin1

19条回答
  •  执笔经年
    2020-11-29 16:51

    Here what my solution PhpMyAdmin / Fedora 29 / MySQL 8.0 (for example):

    set sql_mode='SOMETHING'; doesn't work, command call successful but nothing was change.

    set GLOBAL sql_mode='SOMETHING'; change global configuration permanent change.

    set SESSION sql_mode='SOMETHING'; change session configuration SESSION variable affects only the current client.

    https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html

    So I do this :

    • Get SQL_MODE : SHOW VARIABLES LIKE 'sql_mode';
    • Result : ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
    • Remove on the result : NO_ZERO_IN_DATE,NO_ZERO_DATE
    • Set new configuration : set GLOBAL SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

    You can remove or add other mode in the same way.

    This is helpful to change global for using and testing frameworks or sql_mode must be specified in each file or bunch of queries.

    Adapted from a question ask here : how-can-i-disable-mysql-strict-mode

    Example : install latest Joomla 4.0-alpha content.

    Edit: In PhpMyadmin, if you have the control of the server, you can change the sql_mode (and all others parameters) directly in Plus > Variables > sql_mode

提交回复
热议问题