MySQL 5.7 Invalid default value for 'CREATE_TIME' 報錯的解決方法
阿新 • • 發佈:2019-02-13
由於資料庫的升級,今天在匯入從MySQL 5.6匯出來的SQL檔案時報錯:
mysql> source backup.sql
ERROR 1067 (42000): Invalid default value for 'CREATE_TIME'
因為MySQL 5.6以後timestamp設定預設值規則改變,不能為0000 00-00 00:00:00
解決方法:
檢視sql_mode:
mysql> show session variables like '%sql_mode%';
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
1 row in set (0.01 sec)
修改sql_mode,去掉NO_ZERO_IN_DATE
,NO_ZERO_DATE
:
mysql> set 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> source cms_user.sql
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.03 sec)