MySQL throws error 1406 when an INSERT or UPDATE attempts to write a value longer than the column's defined size. Fix by resizing the column, validating input data, or correcting the data type.
ERROR 1406 (SQLSTATE 22001) occurs when MySQL receives data that exceeds the maximum length defined for a column during an INSERT or UPDATE operation. The server enforces this limit to maintain data integrity and prevent silent data loss. The error message format is "Data too long for column '%s' at row %ld", identifying the specific column and row that caused the failure. MySQL immediately stops the statement and rolls back any changes, leaving the table in a consistent state.
First, inspect the table structure to see the current column definition:
SHOW CREATE TABLE your_table_name;or
DESCRIBE your_table_name;Identify the column that triggered error 1406 and note its current data type and length (e.g., VARCHAR(100)).
Check how long the data actually is. In most applications, this means inspecting the raw input or logging the exact value that failed:
SELECT CHARACTER_LENGTH(your_column) FROM your_table_name WHERE your_column IS NOT NULL ORDER BY CHARACTER_LENGTH(your_column) DESC LIMIT 5;This query shows the longest 5 values in the column, helping you determine the required minimum size.
Increase the column size to accommodate your data. Calculate the required length based on your longest values plus a safety margin:
ALTER TABLE your_table_name MODIFY COLUMN your_column VARCHAR(500);For very large text, use TEXT, MEDIUMTEXT, or LONGTEXT:
ALTER TABLE your_table_name MODIFY COLUMN your_column TEXT;This is the most common and recommended fix. It preserves all data and maintains data integrity.
If the error involves a BIT column, ensure values are prefixed with b instead of quoted strings:
-- Wrong (causes ERROR 1406)
UPDATE your_table SET is_active = '1' WHERE id = 9;
-- Correct
UPDATE your_table SET is_active = b'1' WHERE id = 9;BIT(1) accepts only binary values (b'0' or b'1'), not string representations.
Implement client-side or server-side validation to reject oversized input before it reaches the database. For example, in a web form:
// JavaScript validation
const maxLength = 100;
if (userInput.length > maxLength) {
alert(`Input must be ${maxLength} characters or less`);
return;
}This prevents the error from occurring in the first place and provides immediate user feedback.
Character Set and Collation: If your table uses UTF-8, be aware that multi-byte characters (like emoji or non-Latin scripts) consume more bytes than ASCII. For example, a VARCHAR(100) in UTF-8 can hold fewer emoji than ASCII letters. Check your table's character set with SHOW CREATE TABLE and consider using UTF-8 collations that account for multi-byte lengths.
Strict SQL Mode: Modern MySQL (5.7+) enforces STRICT_TRANS_TABLES by default. Some legacy systems have this mode disabled, which causes MySQL to silently truncate oversized data instead of raising error 1406. Relying on silent truncation risks data loss. Always resize columns or validate input rather than disabling strict mode.
BIT Column Edge Case: A common mistake is inserting quoted strings into BIT columns. BIT(1) is exactly 1 bit wide; inserting the string '1' (8 bits in ASCII) exceeds the column size. Always use b'0' or b'1' syntax for binary values.
ERROR 1064: You have an error in your SQL syntax
How to fix "ERROR 1064: You have an error in your SQL syntax" in MySQL
ERROR 1054: Unknown column in field list
Unknown column in field list
ER_WINDOW_RANGE_FRAME_NUMERIC_TYPE (3589): RANGE frame requires numeric ORDER BY expression
RANGE frame requires numeric ORDER BY expression in MySQL window functions
CR_ALREADY_CONNECTED (2058): Handle already connected
How to fix "CR_ALREADY_CONNECTED (2058): Handle already connected" in MySQL
ER_WINDOW_DUPLICATE_NAME (3591): Duplicate window name
How to fix ER_WINDOW_DUPLICATE_NAME (3591) in MySQL window functions