Quick revision
The short answer
Emoji need 4 bytes in UTF-8, but MySQL's old utf8 character set, now called utf8mb3, stores at most 3 bytes per character, so MySQL either rejects the value with Incorrect string value or, when the connection itself cannot carry it, replaces each character with a question mark. The fix is utf8mb4 at every layer: the server default, the database, the tables and columns (converted with ALTER TABLE ... CONVERT TO CHARACTER SET utf8mb4, minding index length limits), the JDBC connection, and anything in between such as proxies or ETL jobs.
What to remember
In this answer, we saw that emoji need 4 bytes in UTF-8 while MySQL's old utf8, utf8mb3, stores at most 3. A utf8mb3 column rejects them with Incorrect string value, and a utf8mb3 connection silently turns them into question marks. The fix is utf8mb4 everywhere: server defaults, database, tables converted with CONVERT TO CHARACTER SET while watching index key limits, the Connector/J connection, and every proxy or ETL job in between, checked end to end by looking at the bytes.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Emoji need 4 bytes in UTF-8, but MySQL's old utf8 character set, now called utf8mb3, stores at most 3 bytes per character, so MySQL either rejects the value with Incorrect string value or, when the connection itself cannot carry it, replaces each character with a question mark. The fix is utf8mb4 at every layer: the server default, the database, the tables and columns (converted with ALTER TABLE ... CONVERT TO CHARACTER SET utf8mb4, minding index length limits), the JDBC connection, and anything in between such as proxies or ETL jobs.
Why this question is asked
Encoding bugs are frustrating because the data looks fine in the Java code, fine in the HTTP request, and broken only after it has been to the database and back. Interviewers ask this as a debugging question because fixing it properly means following a character through every layer and knowing which ones can silently change it. In this answer, we will recap character sets and why emoji are special, see the two symptoms and what causes each, and then fix the server, the schema, the connection and the layers in between, and finally check that the fix worked.
1A Quick Recap of Character Sets and UTF-8
A character set defines which characters can be stored and how they are turned into bytes. UTF-8 encodes every Unicode character in 1 to 4 bytes: ASCII letters take 1 byte, most European accented letters 2, most Chinese and Japanese characters 3, and characters outside the Basic Multilingual Plane, which includes emoji, take 4. The grinning face, U+1F600, is the four bytes F0 9F 98 80, which is exactly what the error message shows.
MySQL added UTF-8 support early with a character set it called utf8, which stores at most 3 bytes per character. It cannot store any 4-byte character at all. The complete encoding was added later as utf8mb4. MySQL now calls the old one utf8mb3 and has deprecated it; utf8 is still an alias for utf8mb3 in current versions, though that is planned to change, so we always write utf8mb4 explicitly.
2The Two Symptoms and Their Causes
The two symptoms come from two different places. If the column is utf8mb3 and the connection is utf8mb4, the 4-byte character reaches the server intact and the server cannot store it. In strict SQL mode, the default, the insert fails. If the connection itself is utf8mb3 or another charset that cannot carry emoji, the driver or server converts the text before it reaches the column, and characters that cannot be represented become question marks, which is the '????' case.
Notice the second case carefully: the stored value really is a question mark. Data damaged this way cannot be recovered from the database; it has to be entered again or restored from the original source.
3Fixing the Server, Database and Tables
We fix the schema from the outside in. MySQL 8.0 and later already default to utf8mb4 with the collation utf8mb4_0900_ai_ci, but databases and tables created on older versions keep their old settings, and a column's character set is what actually counts.
Two catches. First, CONVERT TO CHARACTER SET rebuilds the table with a full copy, so on large tables we run it through gh-ost or pt-online-schema-change. Second, index key length: with utf8mb4 every character may take 4 bytes, so an index on VARCHAR(255) needs up to 1,020 bytes. InnoDB's limit is 3,072 bytes per index key with the DYNAMIC row format, the default, which is fine for single columns but can be exceeded by composite indexes over several long columns. Old tables with COMPACT or REDUNDANT row format have a 767-byte limit, which is where the old VARCHAR(191) habit came from; converting them to DYNAMIC removes it. Also note that utf8mb4_0900_ai_ci compares differently from older collations, so a conversion can create unique key conflicts; check before converting.
4Fixing the Connection
The connection has its own character set, and it must also be utf8mb4. With MySQL Connector/J, setting characterEncoding=UTF-8 makes the driver use utf8mb4 in recent versions; older drivers mapped it to utf8mb3 and needed the server to be configured accordingly, so check your driver version. We can also name the collation explicitly with connectionCollation.
Running that SHOW from the application, for example in a small diagnostic endpoint or a test, is more reliable than checking it from a console, because the console has its own settings.
5Checking Every Layer in Between
A single layer with the wrong setting is enough to break the chain. Between the Java string and the column there may be a connection proxy, a message queue, an ETL job that copies data between databases, a CSV export and import, or a reporting tool. Each one that decodes and re-encodes text must use UTF-8 with 4-byte support. A useful test is to send a known value through the whole path and look at its bytes at the end.
- Browser or mobile clientUTF-8 request body
- Spring Boot applicationJava strings are Unicode
- JDBC connection
characterEncoding=UTF-8, utf8mb4 session - Proxy, queue or ETL jobmust not re-encode
- Table columnCHARACTER SET utf8mb4
- Server and database defaultsutf8mb4 for new objects
6 layers, from the top down. Step through them one at a time.
When the hex at the end is F09F9880 for the emoji, every layer is correct. If it is 3F, some layer replaced it; if it is a longer sequence such as C3B0C5B8..., some layer decoded UTF-8 bytes as Latin-1 and encoded them again, which is called mojibake.
6Follow-up questions
Why does the error mention the column and not the connection?
Because in that case the 4-byte character reached the server intact through a utf8mb4 connection, and only the column could not hold it. When the connection is the weak layer, there is no error at all, just question marks, which is why that case is harder to spot.
Does utf8mb4 make tables bigger?
Not for the same text. UTF-8 is variable length, so ASCII still takes 1 byte per character in utf8mb4. Only the maximum possible size changes, which matters for index key limits and for some in-memory sorting.
Should we use utf8mb4_0900_ai_ci or another collation?
utf8mb4_0900_ai_ci is a good default for general text: it is based on modern Unicode rules and fast. Columns such as usernames or codes may need an accent-sensitive or binary collation instead, because ai_ci treats values that differ only by accent or case as equal.
7Conclusion
In this answer, we saw that emoji need 4 bytes in UTF-8 while MySQL's old utf8, utf8mb3, stores at most 3. A utf8mb3 column rejects them with Incorrect string value, and a utf8mb3 connection silently turns them into question marks. The fix is utf8mb4 everywhere: server defaults, database, tables converted with CONVERT TO CHARACTER SET while watching index key limits, the Connector/J connection, and every proxy or ETL job in between, checked end to end by looking at the bytes.
Open with
Emoji are 4-byte characters in UTF-8, and MySQL's old utf8 character set, which is really utf8mb3, can store at most 3 bytes per character. So there are two failure modes.
Then, if they want more
If the connection carries the emoji correctly but the column is utf8mb3, strict mode rejects the insert with Incorrect string value and the bytes F0 9F and so on. If the connection itself is utf8mb3, the text is converted before it reaches the column and the emoji become question marks, and that data is lost for good.
I would fix it end to end. On the server, utf8mb4 is the default in MySQL 8 with utf8mb4_0900_ai_ci, but I would set the database default and then convert each table with ALTER TABLE CONVERT TO CHARACTER SET utf8mb4, using gh-ost for large tables because it rebuilds the table.
I would check index key lengths, since utf8mb4 can need 4 bytes per character and InnoDB's limit is 3,072 bytes per key, or 767 on old row formats. Then the connection: in Connector/J, characterEncoding UTF-8 maps to utf8mb4 in recent versions, but I would check the driver version and confirm with SHOW SESSION VARIABLES from the application.
Finally I would make sure no proxy or ETL job re-encodes the text, by sending a known emoji through the whole path and checking its hex at the end.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- MySQL 8.0
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A Spring Boot app stores user names in MySQL and emoji become '????' or the insert fails...": https://scrivio-interview-library.netlify.app/databases/mysql/912d60d972/