Skip to content

MySQL "ERROR 1366: Incorrect string value" on cPanel — the emoji-and-charset insert failure

Saving a post or order fails with "Incorrect string value" — usually an emoji or accented character hitting a utf8 (not utf8mb4) column. Here is how to find the narrow column and widen it safely.

ERROR 1366 (HY000): Incorrect string value: '\xF0\x9F\x98\x80...' for column 'x' at row 1 means MySQL was asked to store a character the column’s character set cannot represent. The byte sequence in the error (\xF0\x9F...) is a dead giveaway: that four-byte pattern is a UTF-8 emoji or a supplementary character, and the column it is going into is declared utf8 — which in MySQL is a misnomer for a three-byte subset that cannot hold emoji or many CJK characters. The save fails, the user sees a generic error, and the data is silently rejected. The fix is to find the specific column (not the whole database — only the narrow one matters) and migrate it to utf8mb4, the genuine four-byte UTF-8.

What’s happening

MySQL’s historical utf8 character set (alias utf8mb3) stores at most three bytes per character. That covers the entire Basic Multilingual Plane but excludes everything that needs four bytes — emoji, many less-common CJK ideographs, some mathematical symbols. When an application sends a four-byte character to a utf8/utf8mb3 column, the server cannot encode it and, under a strict SQL mode, rejects the whole INSERT/UPDATE with 1366 rather than truncating it.

The error names the column and shows the rejected bytes, which makes it precise. The fix is to convert that column (and ideally its table) to utf8mb4. But there is a connection-level half to this: even a utf8mb4 column will throw 1366 if the connection is using a utf8/latin1 character set, because the bytes get mangled before they reach the column. So a complete fix has two parts — widen the storage and set the connection charset — and on cPanel both the application config and the server defaults are in play. Note also that utf8mb4 indexes are wider (4 bytes/char), so very long indexed VARCHAR columns can hit the 767/3072-byte index-prefix limit during conversion; that is a known wrinkle, not a reason to avoid the migration.

How to verify

The error already names the column. Confirm that column’s character set:

# What charset/collation does the named column actually use?
mysql -e "SELECT character_set_name, collation_name FROM information_schema.columns
          WHERE table_schema='cpuser_dbname' AND table_name='wp_posts' AND column_name='post_content';"

# Survey the whole table — which columns are still utf8/utf8mb3?
mysql -e "SHOW FULL COLUMNS FROM cpuser_dbname.wp_posts;" | grep -i utf8

Check the table and database defaults, and the connection charset:

# Table default charset
mysql -e "SHOW CREATE TABLE cpuser_dbname.wp_posts\G" | grep -i charset

# Server-wide defaults new objects inherit
mysql -e "SHOW VARIABLES LIKE 'character_set_server'; SHOW VARIABLES LIKE 'collation_server';"

# What charset does a connection negotiate by default?
mysql -e "SHOW VARIABLES LIKE 'character_set_client'; SHOW VARIABLES LIKE 'character_set_connection';"

For WordPress, the constants in wp-config.php control the connection charset it requests:

# Should be utf8mb4 for a modern WordPress
grep -E "DB_CHARSET|DB_COLLATE" /home/cpuser/public_html/wp-config.php

The fix

  1. Convert the named column to utf8mb4 — the minimal fix is the column the error points at. ALTER TABLE cpuser_dbname.wp_posts MODIFY post_content LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;. This widens just that column so the four-byte character fits. If several text columns in the table can receive user input, convert the whole table instead (next step) rather than chasing them one error at a time.
  2. Convert the whole table when many columns take input — ALTER TABLE cpuser_dbname.wp_posts CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; migrates every text column and the table default in one statement. Take a backup of the table first (mysqldump of just that table), because CONVERT TO rewrites the table and is not instant on large tables.
  3. Set the connection charset to utf8mb4 — a utf8mb4 column still 1366s if the connection speaks utf8. For WordPress, ensure define('DB_CHARSET', 'utf8mb4'); and leave DB_COLLATE empty in wp-config.php. For custom code, run SET NAMES utf8mb4; (or mysqli_set_charset($link,'utf8mb4')) right after connecting. Both halves — column and connection — must be utf8mb4 or the error persists.
  4. Make new tables inherit utf8mb4 server-wide — so this stops recurring for future databases, set character-set-server=utf8mb4 and collation-server=utf8mb4_unicode_ci under [mysqld] in /etc/my.cnf and restart MySQL. cPanel hosts running MariaDB 10.6+ often already default to this; older servers may still default to latin1 or utf8mb3, which is why fresh databases keep reproducing the problem.
  5. Handle the index-length limit during conversion — if CONVERT TO utf8mb4 errors with “Specified key was too long; max key length is 767 bytes”, the table is on the old InnoDB row format. Confirm innodb_large_prefix=ON (default on modern servers) and the table uses ROW_FORMAT=DYNAMIC or COMPRESSED; ALTER TABLE ... ROW_FORMAT=DYNAMIC; before converting, or shorten an over-long indexed VARCHAR. This is the one conversion snag worth anticipating.
  6. Decide on the collation deliberately — utf8mb4_unicode_ci (or utf8mb4_unicode_520_ci) sorts more correctly across languages; utf8mb4_general_ci is faster but less accurate; MySQL 8’s utf8mb4_0900_ai_ci is its default but absent in MariaDB. Pick one and use it consistently across the database so joins between columns of differing collations do not throw “Illegal mix of collations” later.
  7. Re-test the exact save that failed — after converting the column and fixing the connection charset, repeat the action that produced 1366 (post the emoji, place the order, save the name with the accented character). Confirm the data lands and reads back correctly, not just that the error stopped — a connection-charset mismatch can suppress the error while still storing mojibake. A clean round trip of the original character is the proof.

The 1366 is precise by design: it hands you the column and the rejected bytes, and the recurring real cause on cPanel is a utf8/utf8mb3 column meeting an emoji. Widen the storage to utf8mb4, set the connection to match, and make the server default utf8mb4 so it stops coming back. Stack Harbor runs utf8mb4 migrations and charset cleanups under WHM server management — start a conversation when saves fail on special characters.