Insert Chinese error 1406 (22001): Data too long for column ' name ' at row 1

Source: Internet
Author: User

1. Execute the following command before importing the data:
Set SESSION sql_mode= ';

Change the mode by setting the Sql_mode variable. After installing MySQL under Linux, the default Sql-mode value is empty, in which case MySQL performs an irregular check, such as a date field can be inserted in ' 0000-00-00 00:00:00 ' and if the length of the field to be inserted exceeds the length defined by the column, then MySQL will not terminate the operation, but will automatically truncate the subsequent character to continue the insert operation.

But if we want to make an error if the length exceeds the limit, then we can set Sql_mode to Strict_trans_tables, as follows:
Mysql> set session sql_mode= ' Strict_trans_tables '
So we do the same thing again, and MySQL tells us that the inserted value is too long and the operation is terminated as follows:
Mysql> INSERT into T5 values (' ABCD ');
ERROR 1406 (22001): Data too long for column ' C1 ' at row 1

SQL mode and data validation SQL mode can also be implemented for data validation and transfer functions such as:

    1. Validation date data legitimacy.
    2. During insert or update, if 0 is removed (or mod (x,0)), an error is generated
    3. Treat ' ' ' as the identifier quotation mark (' ' ' quotation mark character)
    4. Disables the backslash character (' \ ') as an exit character within a string. When No_backslash_escapes mode is enabled, the backslash becomes a normal character.
    5. Will | | Treated as a string join operator (+) (same as concat ()), not as or.
Sql_mode values that are used frequently
Sql_mode Value Description
Ansi Change the syntax and behavior to make it more compliant with standard SQL.
Strict_trans_tables If the given value cannot be inserted into the transaction table, the statement is discarded. For non-transactional tables, if the value appears in line 1th of a single statement or multiline statement, the statement is discarded. A more detailed description is given later in this section.
Traditional Make MySQL behaves like a "traditional" SQL database system. A simple description of the pattern is "give an error instead of a warning" when an incorrect value is inserted in the column. Note: Once you find an error, discard insert/update immediately. If you use a non-transactional storage engine, this is not what you want, because the data changes made before the error do not "scroll" and the result is "only part of the update".

Note: If you set the value of Sql_mode to the next two values (that is, we mean strict mode), then when inserting or updating an incorrect value in the column, MySQL will give an error and discard the insert/update operation. These two modes are recommended in our general application instead of using the default NULL or ANSI mode. However, it is important to note that if the database is running in strict mode and your storage engine does not support transactions, there is a risk of data inconsistency, such as two DML statements in a set of SQL, if there is a problem in the following, but the previous operation succeeded, Then MySQL cannot roll back the previous operation. So setting up Sql_mode requires the application to weigh the pros and cons to get a suitable choice.

Insert Chinese error 1406 (22001): Data too long for column ' name ' at row 1

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.