Mysql data import failed (sql_mode)

Prepare to build a test library environment locally and export the structure and data of the remote test library. In the process of restoring the local database, it has been failing, and I have been doing this before, so I am very puzzled. The error message prompts invalid value for timestamp, and the default value of the time field is set to "0000-00-00 00:00:00". It may be a sql_mode problem through the positioning of Du Niang, query this through the "select @@sql_mode" command:
sql_mode (local library)
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

sql_mode (remote library)
STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION

By comparison, it is found that there are "NO_ZERO_IN_DATE, NO_ZERO_DAT" in the local library sql_mode, and the time contains 0, which is illegal. MySQL 5.0 and

above supports three sql_mode modes: ANSI, TRADITIONAL and STRICT_TRANS_TABLES.
ANSI mode: loose mode, check the inserted data, if it does not meet the defined type or length, adjust or truncate the data type and save it, and report a warning.
TRADITIONAL mode: strict mode, when inserting data into the mysql database, the data is strictly checked to ensure that the wrong data cannot be inserted, and an error error is reported. When used for things, the rollback of things will be done.
STRICT_TRANS_TABLES mode: strict mode, the data is strictly verified, the wrong data cannot be inserted, and an error error is reported.

The common values ​​of sql_mode are as follows:
ONLY_FULL_GROUP_BY:
For GROUP BY aggregation operations, if the column in the SELECT does not appear in the GROUP BY, then this SQL is invalid because the column is not in the GROUP BY clause

NO_AUTO_VALUE_ON_ZERO:
This value affects the self-growing column insertion. By default, inserting 0 or NULL generates the next auto-increment value. This option is useful if the user wants to insert a value of 0 and the column is auto-incrementing.

STRICT_TRANS_TABLES:
In this mode, if a value cannot be inserted into a transactional table, the current operation is interrupted, and there is no restriction on non-transactional tables
NO_ZERO_IN_DATE:
In strict mode, the day and month are not allowed to be zero

NO_ZERO_DATE:
Set this value, the MySQL database does not allow zero dates to be inserted, inserting zero dates will throw an error instead of a warning.

ERROR_FOR_DIVISION_BY_ZERO:
During an INSERT or UPDATE, if data is divided by zero, an error is generated instead of a warning. If this mode is not given, MySQL returns NULL when data is divided by zero

NO_AUTO_CREATE_USER:
disables GRANT from creating users with empty passwords

NO_ENGINE_SUBSTITUTION:
throws an error if the required storage engine is disabled or not compiled. When this value is not set, the default storage engine is used instead, and an exception

PIPES_AS_CONCAT is thrown:
"||" is treated as a string concatenation operator instead of an OR operator, which is the same as the Oracle database, and the character The string concatenation function Concat is similar to

ANSI_QUOTES:
after ANSI_QUOTES is enabled, double quotes cannot be used to quote the string because it is interpreted as an identifier.

If you use mysql, in order to keep the habit of using oracle, you can set the sql_mode of mysql as follows:
Add the following configuration to my.cnf
[mysqld]
sql_mode='ONLY_FULL_GROUP_BY,NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES


Reference: http://blog.csdn.net/wyzxg/article/details/8787878

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326179243&siteId=291194637