MySQL & MariaDB error 1406: Data too long for column
Data too long for column 'name' at row 1 (8.0.46) A string or binary value is longer than the column allows. In strict mode it is rejected; without strict mode it would be silently cut off.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_DATA_TOO_LONG | ER_DATA_TOO_LONG |
| SQLSTATE | 22001 | 22001 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
Data too long for column 'code' at row 1: the column is VARCHAR(5) (or CHAR, BINARY, TEXT …) and the value is longer. Lengths are in characters for text columns and bytes for binary ones.
With strict mode (STRICT_TRANS_TABLES, the default since MySQL 5.7 and in MariaDB) the statement fails. Without it, the value is truncated with warning 1265. On MySQL 5.6, whose default was non-strict, that is how data quietly lost its last characters for years.
Why it happens
- Input longer than the schema expected: names, URLs, user agents, JSON.
- Moving an application from MySQL 5.6 (non-strict) to 5.7+/MariaDB: inserts that used to be truncated now fail.
- Fixed-width
LOAD DATA … FIELDS TERMINATED BY ''into a utf8mb4 table: the field widths are computed for the wider character set and every row fails with 1406 on MySQL 8.0+ and MariaDB. See our fixed-width import guide.
How to fix it
- Widen the column:
ALTER TABLE c MODIFY code VARCHAR(20);(orTEXTfor unbounded text). - Validate length in the application before inserting.
- Don’t fix it by switching strict mode off: that turns the error back into silent truncation.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database and the test data:CREATE DATABASE demo; USE demo; CREATE TABLE c (code VARCHAR(5));Run:
INSERT INTO c VALUES ('ABCDEFG');
You get: Data too long for column 'code' at row 1(11.8.9)
Verified fixes
Widen the column (or validate input length in the application)
ALTER TABLE c MODIFY code VARCHAR(20); INSERT INTO c VALUES ('ABCDEFG'); SELECT code FROM c;
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| Insert a value longer than the column (strict mode) repro | ≠ | ✓ 1406 | ✓ 1406 | ✓ 1406 | ✓ 1406 | ✓ 1406 | ✓ 1406 | ✓ 1406 | ✓ 1406 |
| Without strict mode the value is silently cut to fit (warning 1265) version check | ⚠ 1265 | ⚠ 3090,1265 | ⚠ 1265 | ⚠ 1265 | ⚠ 1265 | ⚠ 1265 | ⚠ 1265 | ⚠ 1265 | ⚠ 1265 |
| Widen the column (or validate input length in the application) fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
What the warnings and failures say (3)
- Insert a value longer than the column (strict mode) (MySQL 5.6): expected error 1406 did not occur
- Without strict mode the value is silently cut to fit (warning 1265) (MySQL 5.6, MySQL 8.0, MySQL 8.4, MySQL 9, MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): warning 1265: Data truncated for column 'code' at row 1
- Without strict mode the value is silently cut to fit (warning 1265) (MySQL 5.7): warning 3090: Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.; warning 1265: Data truncated for column 'code' at row 1
Related errors
Where this error shows up in our guides
- Import fixed width/row format · FIELDS TERMINATED BY '' (fixed-row format, original) MySQL 8.0 8.4 9MariaDB 10.6 10.11 11.4 11.8
- Import fixed width/row format · Fixed-row format into an INT column MySQL 8.0 8.4 9MariaDB 10.6 10.11 11.4 11.8
- Import fixed width/row format · Fixed-row format with LOAD DATA ... CHARACTER SET latin1 (utf8mb4 table) MySQL 8.0 8.4 9MariaDB 10.6 10.11 11.4 11.8