Common SQL Errors

MySQL Error 1406: ER_DATA_TOO_LONG - How to Fix and Prevent

Galaxy Team
August 7, 2025

<p>MySQL Error 1406 appears when an INSERT or UPDATE value exceeds the defined length of its target column, violating the column size limit.</p>

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1406 ER_DATA_TOO_LONG?

<p>MySQL Error 1406: ER_DATA_TOO_LONG occurs when a value you try to store exceeds the column’s length definition. Trim or truncate the data, enlarge the column with ALTER TABLE, or switch to an appropriate data type to resolve the issue.</p>

Error Highlights

Typical Error Message

Data too long for column '%s' at row %ld

Error Type

Data Error

Language

MySQL

Symbol

ER_DATA_TOO_LONG

Error Code

1406

SQL State

22001

Explanation

Table of Contents

What is MySQL error 1406 ER_DATA_TOO_LONG?

Error 1406 - ER_DATA_TOO_LONG is raised when MySQL receives a value longer than the target column’s declared length or size during INSERT or UPDATE.

The exact message is: Data too long for column '%s' at row %ld. MySQL stops the statement, rolls back the row, and returns SQLSTATE 22001 - string data right truncation.

What Causes This Error?

The error fires when string, binary, or numeric data exceeds column length, precision, or scale. It also occurs with improper character set conversions that expand byte length.

MySQL additionally flags the error when strict SQL mode is active; in non-strict mode, excess bytes may be silently truncated.

How to Fix MySQL Error 1406 ER_DATA_TOO_LONG

First confirm the column definition with SHOW CREATE TABLE. Compare defined length to incoming data length. Shorten the value, cast, or pad only within limits.

Alternatively, expand the column using ALTER TABLE ... MODIFY ... or switch to a type with a larger capacity such as TEXT or VARCHAR with a higher length.

Common Scenarios and Solutions

Bulk CSV loads often contain unexpected long strings. Pre-clean the file or load into a staging table with wider columns, then migrate cleaned data.

JSON payloads stored in VARCHAR columns may overflow. Replace the column with JSON or LONGTEXT for safe storage.

Best Practices to Avoid This Error

Validate input lengths at the application layer before executing SQL. Enforce client-side constraints or use parameterized queries that trim values.

Maintain explicit column sizing documentation and automate schema checks in CI pipelines. Monitor application logs for repeated 1406 occurrences to react proactively.

Related Errors and Solutions

Error 1264: Out of range value - raised for numeric overflow. Widen the numeric column or constrain the value.

Error 1366: Incorrect string value - occurs with invalid character set data. Ensure proper encoding and column collation.

Common Causes

Input longer than column length

User-supplied strings, file imports, or concatenations exceed VARCHAR or CHAR limits.

Numeric precision overflow

Values with more digits than DECIMAL or integer types allow trigger the error in strict mode.

Implicit character set expansion

UTF-8 characters can occupy up to 4 bytes, pushing total length beyond defined byte size.

Incorrect column type choice

Storing large blobs or JSON in small VARCHAR columns eventually exceeds capacity.

Related Errors

Error 1264: Out of range value

Thrown when numeric data exceeds column range. Fix by widening numeric types.

Error 1366: Incorrect string value

Raised for invalid encoding in character columns. Ensure proper charset conversion.

Error 1048: Column cannot be null

Occurs when inserting NULL into a NOT NULL column. Provide a value or adjust schema.

FAQs

Does MySQL automatically truncate long data?

Only when strict SQL mode is disabled. In strict mode, MySQL aborts the statement with Error 1406.

Can I ignore Error 1406 with IGNORE?

INSERT IGNORE converts the error into a warning, truncates the value, and inserts the row. Data may be lost.

Will changing VARCHAR to TEXT impact indexes?

Yes. TEXT columns cannot be fully indexed without length limits; you may need prefix indexes.

How does Galaxy help avoid this error?

Galaxy’s SQL editor highlights column lengths during code completion and warns when literals exceed size constraints, reducing 1406 incidents.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo