MySQL 5.7 Invalid default value for 'CREATE_TIME'報錯的解決方法


出處:http://blog.itpub.net/15498/viewspace-2136006/

 

 

由於數據庫的升級,今天在執行從MySQL 5.6導出來的SQL文件時報錯:

mysql> source cms_user.sql
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.04 sec)

ERROR 1067 (42000): Invalid default value for 'CREATE_TIME'
ERROR 1146 (42S02): Table 'ixinnuo_zxpt.cms_user' doesn't exist


因為MySQL 5.6以后timestamp設定默認值規則改變,不能為”0000 00-00 00:00:00”

解決方法:
查看sql_mode:
mysql> show session variables like '%sql_mode%';
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value                                                                                                                                     |
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| 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)

Query OK, 0 rows affected (0.55 sec)

Query OK, 1 row affected (0.07 sec)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM