Website move MySQL 5.7 date type default value cannot set ' 0000-00-00 ' issue

Source: Internet
Author: User
Tags mysql version

Website moved, MySQL version upgraded from 5.6 to 5.7, encountered problems:

After MySQL 5.7 version datetime defaults set ' 0000-00-00 ', an exception occurred:Invalid default value for ' Create_time '

Read the Manual

The date type is used for values with a, a date part, and no time part. MySQL retrieves and displays DATE values in ' yyyy-mm-dd ' format. The supported range is ' 1000-01-01 ' to ' 9999-12-31 '.

MySQL 5.7 uses no_zero_in_date, no_zero_date two options, prohibits 0000 Such date and time, the ideal solution:

Change the date and time format from ' 1000-01-01 ' to ' 9999-12-31 '

And I was using the import and export of SQL files to move, batch replacement a little trouble, a not recommended method, in the MySQL configuration file , reset Sql_mode, remove these two.

Linux:

Modify the my.cnf file and restart MySQL.

Mac:

There is no my.cnf file by default in MacOS, and if you need to customize MySQL, copy any. cnf file in the/usr/local/mysql/support-files/directory. put it in a different directory, as modified above, renamed to My.cnf, and then copied to the/etc directory and then restarted the MySQL will be finished.

Windows:

Restart MySQL after modifying the My.ini file.

Add SQLto [mysqld] -Mode=only_full_group_by,strict_trans_ Tables,error_for_division_by_zero,no_auto_create_user,no

Ways to view Sql-mode:

The MySQL database has an environment variable sql_mode, which defines the SQL syntax that MySQL should support, data validation, etc.

Mysql> Select @ @sql_mode; +----------------------------------------------------------------+      | @ @sql_mode                                                     |      +----------------------------------------------------------------+      |Strict_trans_tables,no_auto_create_user,no_engine_substitution|      +----------------------------------------------------------------+  

viewing system Variables

    MySQL>like'sql_mode%'\g;         *************************** 1 ***************************         Variable_name:sql_mode        value:strict_trans_tables,no_auto_create_user,no_engine_substitution    

Website move MySQL 5.7 date type default value cannot set ' 0000-00-00 ' issue

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.