How to Fix MySQL Error 1406 (ER_DATA_TOO_LONG)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mysql error 1406 when you try to write a value that exceeds the target column size. You fix it by expanding the column definition or validating input length in your app before writing. This failure uses the official symbol ER_DATA_TOO_LONG and returns SQLSTATE 22001. The database engine outputs a message stating that data is too long for a specific column and row. This check stops the engine from cutting off extra characters or extra digits during writes. Your transaction rolls back so

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You see mysql error 1406 when you try to write a value that exceeds the target column size. You fix it by expanding the column definition or validating input length in your app before writing.

This failure uses the official symbol ER_DATA_TOO_LONG and returns SQLSTATE 22001. The database engine outputs a message stating that data is too long for a specific column and row. This check stops the engine from cutting off extra characters or extra digits during writes. Your transaction rolls back so you do not store partial records.

What causes mysql error 1406 in your database

The main trigger for mysql error 1406 is strict SQL mode in the database engine. When strict mode is active, the engine rejects any insert or update that goes over column limits. When strict mode is off, the engine cuts the value to fit and logs a simple warning.

String columns fail when the character count of the input exceeds the defined column limit. Character sets also play a big role in how the engine measures string size. Multi-byte characters like emojis take up more space than basic letters. If a column uses a single-byte character set, multi-byte inputs can trigger size mismatches during conversion.

Numeric columns can trigger this exact error too. Integer columns reject numbers that fall outside their signed or unsigned range. Decimal columns fail when the digits before the decimal point exceed the allowed space. Even a single extra digit at the start of a price or score causes the write to fail.

How to diagnose the failing column and row

Start by reading the full error message in your app logs. The message names the exact column and the row number that caused the failure. If you run a batch insert, the row number points to the bad record in that batch. You can then inspect the source payload to see why that value was so large.

Next, check the table schema to see the current data type and size limit of that column. Compare the schema limit against the length of the incoming value from your app. Do not grant broad database write roles to developers just to debug one bad payload. Instead, use read-only schema checks and masked logs to find the mismatch.

MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You should also check the character set of the client session and the target table. A mismatch between client text encoding and table encoding often inflates string sizes during transfer. Make sure your app sends text in the exact encoding that the column expects.

How to fix the error in production

You have two safe ways to fix this failure in production. First, if the business rules allow longer values, alter the table to increase the column size. For example, you can widen a text column or switch to a larger integer type. Run schema changes during low traffic windows or use an online schema change tool to avoid table locks.

Second, if the schema limit is correct, fix the input check in your app code. Check the length of user inputs like emails or phone numbers before sending the query. Reject oversize inputs at the API layer and return a clear message to the user. Never disable strict SQL mode in production to bypass this error, because silent truncation corrupts your data.

Check MySQL queries and results on the wire

MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.

Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.

Frequently asked questions

Why did mysql error 1406 start after a database upgrade?

Newer versions turn on strict SQL mode by default. Older setups often ran with strict mode off, which cut off long values instead of blocking the write.

Can a numeric or decimal column trigger error 1406?

Yes, numeric columns trigger this error when a number exceeds the allowed range. Decimal columns also fail when a number has too many digits to the left of the decimal point.

Should I turn off strict mode to fix ER_DATA_TOO_LONG?

No, turning off strict mode lets the database chop off extra data without stopping the query. Keep strict mode on and fix your column size or app checks instead.

The query runs. The emails stay hidden.