1366 🐬 MySQL

MySQL ERROR 1366: Incorrect string value: '\xF0\x9F\x98\x80' for column

The text contains characters (usually emoji) that the column’s character set can’t store — the column or connection is utf8/utf8mb3 instead of utf8mb4.

Seen on: MySQL PHP

Meaning

MySQL’s legacy utf8 stores at most 3 bytes per character. Emoji and some CJK characters need 4 bytes (\xF0…). Both the column/table and the connection charset must be utf8mb4.

Common causes

  • Column or table uses utf8/utf8mb3 or latin1
  • Connection charset not utf8mb4 (DSN missing charset=utf8mb4)
  • Database default charset outdated after migration

⚡ Quick fix

  1. Convert the table: ALTER TABLE t CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  2. Use charset=utf8mb4 in the connection DSN
  3. Set database default to utf8mb4 for new tables

Detailed fix by platform

MySQL

  1. Convert database and table:
    sql
    ALTER DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    ALTER TABLE comments CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

PHP

  1. PDO: mysql:host=…;dbname=…;charset=utf8mb4. On old MySQL 5.6, indexed VARCHAR(255) columns may need to shrink to 191 for utf8mb4.

How to diagnose

  1. Column — SHOW FULL COLUMNS FROM t — collation?
  2. Connection — SHOW VARIABLES LIKE 'character_set_%' from the app connection
  3. Data — Emoji or 4-byte characters present?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.