Home >Database >Mysql Tutorial >How to Resolve MySQL Error 1406: Data Too Long for Column?
Error Code: 1406 – Managing Excessively Long Data in MySQL
When attempting to insert data into a MySQL table, users may encounter Error Code 1406: Data too long for column. This error occurs when the data exceeds the length specified for the target column's data type.
Cause of the Error:
In the example provided, the VARCHAR column TESTcol has a length of 45 characters. However, the attempted insertion of data with a length of 47 characters triggers the error. By default, MySQL will truncate any values that exceed the specified column width.
Solution:
To bypass this error, users can consider two options:
Adjust Column Length: Increase the length of the target column to accommodate the longer data. This can be achieved through an ALTER TABLE statement, such as:
ALTER TABLE TEST MODIFY COLUMN TESTcol VARCHAR(60);
Disable Strict Mode: In MySQL, strict mode controls the level of data validation performed during insert operations. Disabling strict mode allows the insertion of values that exceed column lengths. However, this option may compromise data integrity and is not recommended for most scenarios.
SET @@global.sql_mode= '';
Note: Disabling strict mode should be used with caution and only for specific cases where data integrity is not a concern.
The above is the detailed content of How to Resolve MySQL Error 1406: Data Too Long for Column?. For more information, please follow other related articles on the PHP Chinese website!