Home > Database > Mysql Tutorial > How to Resolve MySQL Error 1406: Data Too Long for Column?

How to Resolve MySQL Error 1406: Data Too Long for Column?

Susan Sarandon
Release: 2025-01-03 09:51:39
Original
348 people have browsed it

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:

  1. 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);
    Copy after login
  2. 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= '';
    Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template