MySQL & MariaDB error 1366: Incorrect string value (or incorrect integer value)
Incorrect integer value: '' for column 'lNumber' at row 1 (5.7.44) · Incorrect integer value: '' for column ``.``.`lNumber` at row 0 (10.11.19) A value can't be stored in the column's type or character set. Most often an emoji or other 4-byte character going into a utf8mb3 ("utf8") column, or text going into a number column in strict mode.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_TRUNCATED_WRONG_VALUE_FOR_FIELD | ER_TRUNCATED_WRONG_VALUE_FOR_FIELD |
| SQLSTATE | HY000 | 22007 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
Incorrect string value: '\xF0\x9F\x91\x8D' for column 'txt' at row 1 shows the raw bytes the server couldn’t store. A value starting \xF0 is a 4-byte UTF-8 character (emoji, some CJK and maths symbols), which the 3-byte utf8mb3 character set, called plain utf8 in older versions, can’t hold. Incorrect integer value: 'abc' for column 'i' is the same error for numbers.
In strict mode (the default from MySQL 5.7 and in MariaDB) this is an error. In non-strict mode, which was the MySQL 5.6 default, the value is mangled (? or 0) with only a warning, so data was silently lost.
Why it happens
- Tables created years ago with
CHARSET=utf8(utf8mb3), now receiving emoji from web forms or mobile apps. - The connection character set doesn’t match the data: a client sending UTF-8 while the connection says
latin1. - Strings or empty strings sent for INT, DECIMAL or DATE columns.
How to fix it
- Convert the table to utf8mb4:
ALTER TABLE notes CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;(MariaDB:utf8mb4_unicode_ciorutf8mb4_uca1400_ai_ci). Watch index length limits (1071), because utf8mb4 needs 4 bytes per character. - Make the connection utf8mb4 too:
SET NAMES utf8mb4, orcharset=utf8mb4in the driver DSN. - Validate or convert numeric input in the application; send
NULLrather than''for missing numbers.
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 notes (txt VARCHAR(50) CHARACTER SET utf8mb3);Run:
INSERT INTO notes VALUES ('thumbs up 👍');
You get: Incorrect string value: '\xF0\x9F\x91\x8D' for column `t_0`.`notes`.`txt` at row 1(11.8.9)
Verified fixes
Convert the column (or table) to utf8mb4
ALTER TABLE notes MODIFY txt VARCHAR(50) CHARACTER SET utf8mb4; INSERT INTO notes VALUES ('thumbs up 👍'); SELECT COUNT(*) FROM notes;
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| Store an emoji (4-byte UTF-8) in a utf8mb3 ("utf8") column repro | ≠ | ✓ 1366 | ✓ 1366 | ✓ 1366 | ✓ 1366 | ✓ 1366 | ✓ 1366 | ✓ 1366 | ✓ 1366 |
| A non-numeric string into an INT column version check | ≠ | ✓ 1366 | ✓ 1366 | ✓ 1366 | ✓ 1366 | ✓ 1366 | ✓ 1366 | ✓ 1366 | ✓ 1366 |
| Convert the column (or table) to utf8mb4 fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
What the warnings and failures say (2)
- Store an emoji (4-byte UTF-8) in a utf8mb3 ("utf8") column (MySQL 5.6): expected error 1366 did not occur
- A non-numeric string into an INT column (MySQL 5.6): expected error 1366 did not occur
Related errors
Where this error shows up in our guides
- Basic hash jumbler function · CREATE FUNCTION (NOT DETERMINISTIC, NO SQL) and call it (original) MySQL 5.7 8.0 8.4 9MariaDB 10.6 10.11 11.4 11.8
How the message changed between versions
| MariaDB from | Symbol | Message |
|---|---|---|
| 5.5.68 | ER_TRUNCATED_WRONG_VALUE_FOR_FIELD | Incorrect %-.32s value: '%-.128s' for column '%.192s' at row %lu |
| 10.2.44 | ER_TRUNCATED_WRONG_VALUE_FOR_FIELD | Incorrect %-.32s value: '%-.128T' for column `%.192s`.`%.192s`.`%.192s` at row %lu |
| 11.8.10 | ER_TRUNCATED_WRONG_VALUE_FOR_FIELD | Incorrect %-.32s value: '%-.128sT' for column `%.192s`.`%.192s`.`%.192s` at row %lu |