Incident Response

MySQL ERROR 1265: Data truncated for column

The value does not fit the column, and strict mode refuses to quietly change it. Here is what usually triggers 1265, how to find the offending rows before a long ALTER fails, and why switching strict mode off is the wrong fix on a production database.

· 16 min read · AG Data Team

MySQL ERROR 1265: Data truncated for column means a value did not fit the column it was written to, and MySQL would have had to cut or change it to store it. In strict SQL mode, which is the default, that is an error and the statement stops. Without strict mode, the same thing is only a warning and the changed value is stored.

mysql> INSERT INTO orders (id, status, qty) VALUES (1, 'refunded', 1);
ERROR 1265 (01000): Data truncated for column 'status' at row 1

mysql> ALTER TABLE customers MODIFY name VARCHAR(10);
ERROR 1265 (01000): Data truncated for column 'name' at row 2

The server error reference lists it as WARN_DATA_TRUNCATED, SQLSTATE 01000, message Data truncated for column '%s' at row %ld. The symbol tells you where it came from: this is a warning that strict mode turns into an error. The message names the column, and the row number counts rows in the statement, not the table's primary key. In a multi-row INSERT or LOAD DATA, row 1532 is the 1532nd row of your input.

Why the same statement works on one server and fails on another

According to the SQL mode documentation, the default sql_mode in MySQL 8.4 includes STRICT_TRANS_TABLES. In strict mode, invalid values in data-change statements such as INSERT and UPDATE produce an error. For transactional tables like InnoDB, the whole statement is aborted and rolled back. Without strict mode, MySQL stores an adjusted value and produces a warning.

So when a query "worked yesterday" or "works on the old server", compare the SQL modes before anything else. The documentation also warns that installation programs may set the SQL mode, so the value in an option file can differ from what you expect. Applications can also change it per session at any time.

-- what does the column accept?
SHOW CREATE TABLE orders\G

-- which SQL mode is this session really using?
SELECT @@SESSION.sql_mode, @@GLOBAL.sql_mode;

-- the full list of warnings and notes from the last statement
SHOW WARNINGS;

Run SHOW WARNINGS right after the failing statement. It shows every problem the statement hit, not only the first one.

What usually triggers 1265

-- 1. ENUM / SET value that is not in the list
INSERT INTO orders (id, status) VALUES (1, 'refunded');   -- 1265
-- 2. a number followed by junk
INSERT INTO orders (id, status, qty) VALUES (2, 'new', '12abc');   -- 1265
--    (pure text such as 'abc' gives ERROR 1366 instead)
-- 3. CSV with Windows line endings: the last field ends with \r
LOAD DATA INFILE '/var/lib/mysql-files/orders.csv' INTO TABLE orders
  FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n';
-- 4. ALTER TABLE that narrows a column which already holds wider data
ALTER TABLE customers MODIFY name VARCHAR(10);   -- 1265 at row N

Neighbouring errors look similar but mean something else. 1264 is out of range: a number too large for the type. 1292 is an incorrect date or time value. 1406 is a string too long on insert. The fix for all of them starts the same way: compare the value with the column definition.

Note 1265 on DECIMAL columns is not an error

Insert 1.239 into a DECIMAL(10,2) column and the statement succeeds, even in strict mode. MySQL stores 1.24 and records a Note with code 1265. The rounding documentation shows the same: inserts into DECIMAL and integer columns round half away from zero and report Note 1265. That is usually fine for prices calculated with extra digits. If the extra precision matters, for example for exchange rates or unit costs, the column scale is too small and you need to widen it. Ignoring the note will not help.

How to fix it

  1. Fix the value or the column, whichever is wrong. A new status in the application means the ENUM needs the new member, added before the release that sends it. A typo or a mapping bug in the application means the code needs fixing.
  2. Clean the input for imports. Normalise line endings, trim fields, map empty strings to NULL with a SET clause in LOAD DATA, and convert local formats before the load.
  3. Find the offending rows before you narrow a column. Query for them first, decide what to do with each group, then run the ALTER.
  4. Use IGNORE only when you mean it. According to the documentation, INSERT IGNORE and UPDATE IGNORE turn these errors into warnings and store adjusted values. When both IGNORE and strict mode apply, IGNORE wins. LOAD DATA with IGNORE, or with LOCAL and without REPLACE, also turns data interpretation errors into warnings even under a strict SQL mode (LOAD DATA documentation). That is data loss you agreed to, so check the warnings afterwards.
-- before shrinking a VARCHAR: rows that would not fit
SELECT id, CHAR_LENGTH(name) AS len
FROM customers
WHERE CHAR_LENGTH(name) > 10
ORDER BY len DESC LIMIT 20;

-- before removing an ENUM member: rows that still use it
SELECT status, COUNT(*) FROM orders GROUP BY status;

-- damage left by non-strict mode: the ENUM error value '' (index 0)
SELECT COUNT(*) FROM orders WHERE status + 0 = 0;

Do not switch strict mode off to make the error go away. SET GLOBAL sql_mode = '' affects every client that connects afterwards. From then on, bad ENUM values quietly become '', numbers lose their junk and strings get cut, all with only a warning that nobody reads. The error was protecting your data. In our experience, cleaning up months of silently damaged rows costs far more than fixing the one statement that failed.

On large tables and busy fleets

On a small table, 1265 costs you a retry. On a large production database, the same error can waste hours of work or quietly spread bad data. A few things matter at scale:

-- which live sessions are not running in strict mode?
SELECT t.PROCESSLIST_USER, t.PROCESSLIST_HOST, v.VARIABLE_VALUE AS sql_mode
FROM performance_schema.variables_by_thread v
JOIN performance_schema.threads t USING (THREAD_ID)
WHERE v.VARIABLE_NAME = 'sql_mode'
  AND v.VARIABLE_VALUE NOT LIKE '%STRICT%';

-- appending an ENUM member at the end can be instant
ALTER TABLE orders
  MODIFY status ENUM('new','paid','shipped','refunded') NOT NULL,
  ALGORITHM=INSTANT;

Key takeaways

MySQL Errors Data quality Schema changes
Work with us

Imports or migrations failing on bad data?

We clean up data, check SQL modes across your servers and run schema changes on large MySQL tables without surprises halfway through.

Get in touch More from the blog