Skip to content
MySQL

MySQL Error 1406

Data too long for column

Applies to: MySQL 5.7, 8.0 and 8.4 (an error under strict sql_mode, the default since 5.7; a truncation warning without it)
Last technically reviewed 24 October 2026 on MySQL 8.0.46
The full message
ERROR 1406 (22001): Data too long for column 'name' at row 1
Other forms of this message
Second row of a multi-row INSERT
ERROR 1406 (22001): Data too long for column 'name' at row 2
PHP PDO
SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'name' at row 1
Strict mode off, or INSERT IGNORE (a warning; the value is cut)
Warning (Code 1265): Data truncated for column 'name' at row 1
Error number
1406
SQLSTATE
22001
Symbol
ER_DATA_TOO_LONG
Product
MySQL Server
Versions
MySQL 5.7, 8.0 and 8.4 (an error under strict sql_mode, the default since 5.7; a truncation warning without it)
Last reviewed
24 October 2026

What it means

Error 1406 means a string or binary value is longer than the column allows, for example 15 characters into VARCHAR(10), so strict mode rejected the statement instead of cutting the value.

Every string and binary column has a maximum length: VARCHAR(n) and CHAR(n) hold n characters, VARBINARY(n) and BINARY(n) hold n bytes, and the TEXT and BLOB types have byte limits (TINYTEXT 255 bytes, TEXT 65,535 bytes). When an INSERT, UPDATE or LOAD DATA would store a longer value, MySQL in strict sql_mode (the 8.0 default) stops the statement with 1406. The message names the column and the row within the statement, so at row 2 points to the second row of a multi-row INSERT.

VARCHAR and CHAR lengths count characters, not bytes, so in a utf8mb4 column VARCHAR(5) accepts five accented characters. SQLSTATE 22001 is the standard code for "string data, right truncated". Without strict mode the value is silently cut to fit and only warning 1265 is raised. The SQL Server equivalent is error 8152; MySQL's neighbouring errors are 1366 for values of the wrong type and 1264 for numbers out of range.

Common causes

  • User input or an API field is longer than the column: a full name, address, URL, user agent string or product title.
  • An import or INSERT ... SELECT copies from a wider source column, or from a source that has extra spaces or padding.
  • An UPDATE builds a longer value, for example CONCAT(sku, '-RETIRED') or appending to a notes column.
  • A code column has the wrong size: a three-letter code such as 'GBR' written to CHAR(2).
  • A TINYTEXT or TEXT column reaches its byte limit, or a BIT(1) column is given a value that needs more than one bit.

Diagnose it

Read-only These statements only read metadata (information_schema, performance_schema and SHOW statements) or your own data. They do not change data, privileges or configuration, so they are safe to run first.

Check the declared length of the column

SELECT column_name, column_type, character_maximum_length,
       character_octet_length, character_set_name
FROM information_schema.columns
WHERE table_schema = DATABASE()
  AND table_name = 'customers'
ORDER BY ordinal_position;
What to look for

character_maximum_length is the limit in characters for CHAR and VARCHAR (bytes for BINARY, VARBINARY and the BLOB types); character_octet_length is the limit in bytes.

Find the values that are too long before loading them

SELECT id, name, CHAR_LENGTH(name) AS chars, LENGTH(name) AS bytes
FROM staging_customers
WHERE CHAR_LENGTH(name) > 10   -- the target column is VARCHAR(10)
ORDER BY chars DESC;
What to look for

Each row that would fail. Compare chars with the VARCHAR or CHAR length, and bytes with the limit of a BINARY, VARBINARY, TEXT or BLOB column.

See the longest value a column already holds

Useful before shrinking a column or when choosing a new length.

SELECT MAX(CHAR_LENGTH(name)) AS longest_chars,
       MAX(LENGTH(name))      AS longest_bytes
FROM customers;
What to look for

The longest stored value. A new limit should leave room above it for real data.

Confirm the session is in strict mode

SELECT @@SESSION.sql_mode, @@GLOBAL.sql_mode;
What to look for

STRICT_TRANS_TABLES or STRICT_ALL_TABLES makes an over-long value an error. If another environment truncates silently instead, its sql_mode is different; align it to strict rather than the other way round.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Widen the column to fit real data

Changes schema

When the data is valid and the column is simply too small, increase the length. Repeat every existing attribute in MODIFY (NOT NULL, DEFAULT, COMMENT, character set), because MODIFY replaces the whole column definition.

Caution: Some VARCHAR length changes rebuild the table (for example when the length prefix grows from one byte to two at 256 bytes), which can take a long time on a large table; check the online DDL documentation and run it in a maintenance window.

ALTER TABLE customers MODIFY name VARCHAR(100);

Validate the length in the application

Client or network side

Check input length against the column before saving and show the user a clear message, such as "name must be 100 characters or fewer". Count characters, not bytes (in PHP use mb_strlen), to match how VARCHAR counts.

Shorten values on purpose during a load

Changes data

If the business accepts shortened values (for example a display title), trim spaces and cut explicitly with LEFT, so the decision is visible in the code rather than hidden in a warning.

Caution: This discards characters. Only use it where losing the end of the value is acceptable, never for codes, identifiers, URLs or anything compared later.

INSERT INTO customers (id, name)
SELECT id, LEFT(TRIM(name), 10)
FROM staging_customers;

Use a TEXT type for long free text

Changes schema

For comments, descriptions and other open-ended text, TEXT (65,535 bytes) or MEDIUMTEXT (16 MB) is a better fit than an ever-growing VARCHAR. TINYTEXT only holds 255 bytes.

ALTER TABLE products MODIFY notes TEXT;

Examples

A name longer than VARCHAR(10)

CREATE TABLE customers (
    id   INT PRIMARY KEY,
    name VARCHAR(10)
);

INSERT INTO customers (id, name) VALUES (1, 'Alexandra Smith');  -- 15 characters
Result
ERROR 1406 (22001): Data too long for column 'name' at row 1

Reproduced on MySQL 8.0.46, 24 October 2026.

The second row of a multi-row INSERT is too long

The whole statement fails: row 1 is not inserted either.

CREATE TABLE customers (
    id   INT PRIMARY KEY,
    name VARCHAR(10)
);

INSERT INTO customers (id, name) VALUES
    (1, 'Ali'),
    (2, 'Bartholomew Jones');
Result
ERROR 1406 (22001): Data too long for column 'name' at row 2

Reproduced on MySQL 8.0.46, 24 October 2026.

An UPDATE that makes a value longer

CREATE TABLE products (
    id  INT PRIMARY KEY,
    sku VARCHAR(12)
);
INSERT INTO products VALUES (2, 'MUG-002');

UPDATE products SET sku = CONCAT(sku, '-RETIRED') WHERE id = 2;  -- 15 characters
Result
ERROR 1406 (22001): Data too long for column 'sku' at row 1

Reproduced on MySQL 8.0.46, 24 October 2026.

More than 255 bytes in a TINYTEXT column

CREATE TABLE products (
    id    INT PRIMARY KEY,
    notes TINYTEXT
);

INSERT INTO products (id, notes) VALUES (1, REPEAT('x', 300));
Result
ERROR 1406 (22001): Data too long for column 'notes' at row 1

Reproduced on MySQL 8.0.46, 24 October 2026.

How to prevent it

Size columns from the real data and the business rule, not from a guess: check the longest values in source systems, leave headroom, and use TEXT for open-ended text. Enforce the same limits in forms and APIs so users get a clear message before the database is reached, and count characters rather than bytes.

Keep strict mode on in every environment. With sql_mode empty (or with INSERT IGNORE), the same INSERT succeeds with warning 1265 and stores the value cut to fit: in our test 'Alexandra Smith' became 'Alexandra ', which nobody notices until the data is wrong.

Common questions

How do I fix MySQL error 1406?

Find the column and row in the message, compare the value's length with the column definition, then either widen the column (ALTER TABLE ... MODIFY), validate the length in the application, or shorten the value on purpose with LEFT if losing the end is acceptable.

Does VARCHAR(10) mean 10 characters or 10 bytes?

Ten characters. In a utf8mb4 column VARCHAR(10) accepts ten characters even if some take several bytes. BINARY, VARBINARY, TINYTEXT, TEXT and the BLOB types have limits in bytes instead.

Why does the same INSERT work on another server?

That server is probably not in strict mode. Without STRICT_TRANS_TABLES MySQL cuts the value to fit and raises only warning 1265, so data is lost silently. Compare SELECT @@GLOBAL.sql_mode on both servers and make the other one strict.

What does "at row 2" mean in the message?

It is the position of the row within the failing statement, not a primary key. In a multi-row INSERT or an INSERT ... SELECT it is the row number in the data being written.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 24 October 2026; examples and diagnostics run on MySQL 8.0.46. Message templates checked against the server's error catalogue (perror) for that version.

Still stuck on a MySQL error?

Browse the full MySQL error library, or get hands-on help from an experienced SQL professional.