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
- A value outside an ENUM or SET list. This is the most common case. The application starts sending a new status such as
'refunded'before the column definition knows it. According to the ENUM documentation, without strict mode MySQL stores a special error value instead: an empty string with index 0. - A number with junk after it.
'12abc'into anINTcolumn gives 1265. Pure text like'abc'gives a different error, 1366 Incorrect integer value. If your 1366 is about strings and character sets, see our guide to MySQL error 1366. - CSV files with Windows line endings. When a file uses
\r\nbutLOAD DATAsplits lines on\n, the last field of every line keeps a trailing\r. If that field is an ENUM, the value no longer matches any member and the load stops with 1265 on the very first line. DeclareLINES TERMINATED BY '\r\n'. - An ALTER TABLE that narrows a column. Shrinking a
VARCHARor removing an ENUM member that rows still use. Here the existing data is the input, and the first row that does not fit stops the ALTER. Note that a plainINSERTof a string that is too long reports a different error, 1406 Data too long, and so can an ALTER that also changes the type, for example fromVARCHARtoCHAR.
-- 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
- 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.
- Clean the input for imports. Normalise line endings, trim fields, map empty strings to
NULLwith aSETclause inLOAD DATA, and convert local formats before the load. - Find the offending rows before you narrow a column. Query for them first, decide what to do with each group, then run the ALTER.
- Use IGNORE only when you mean it. According to the documentation,
INSERT IGNOREandUPDATE IGNOREturn these errors into warnings and store adjusted values. When both IGNORE and strict mode apply, IGNORE wins.LOAD DATAwithIGNORE, or withLOCALand withoutREPLACE, 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:
- Check the data before a long ALTER. Changing a column's data type is only supported with
ALGORITHM=COPY(online DDL documentation). On a table with hundreds of millions of rows, the copy can run for hours and then fail with 1265 at the first row that does not fit, and all that work is thrown away. A pre-check query, ideally run on a replica, costs far less than a failed copy. For running the change itself without blocking traffic, see our guide to MySQL ALTER TABLE without downtime. - Extend ENUMs at the end only. According to the documentation, adding new members to the end of an ENUM or SET list can be done instantly or in place, as long as the storage size does not change. Adding a member in the middle renumbers the existing ones and requires a table copy. Removing or reordering members is a rebuild too, and it also needs the data pre-check above.
- Size batches with failure in mind. On InnoDB, one bad row rolls back the whole multi-row statement. An ETL job that loads 10,000-row batches loses the whole batch because of one dirty value. In our experience, the reliable pattern is to load into a permissive staging table, validate with queries, and move only clean rows into the real table, keeping the rejected rows for someone to review.
- Audit session SQL modes, not only the global value. Frameworks and connection pools can set their own
sql_modeper session. One service running non-strict can fill shared tables with''ENUM values while every other service is strict. The performance_schema.variables_by_thread table shows the session values of live connections. - Keep SQL modes identical across source and replicas. The SQL mode documentation recommends always using the same server SQL mode on the source and the replica, and warns that differing modes cause problems with partitioned tables. Also, after a failover, an application that relied on a lax primary will meet the strict new one in the middle of an incident, which is the worst moment to find out.
-- 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
- ERROR 1265 (01000) is a truncation warning that strict mode turns into an error. The value did not fit the column.
- Typical causes: ENUM or SET values outside the list, numbers with trailing junk, CSV files with
\r\nline endings, and ALTERs that narrow columns holding wider data. - Note 1265 on
DECIMALmeans rounding to the column scale, not a failure. - Fix the data or the definition. Do not disable strict mode globally, because that turns errors into silent data damage.
- On large tables, check the data before a copying ALTER, extend ENUMs only at the end, load through staging tables, and keep SQL modes consistent across sessions and replicas.