What is utf8mb4 and why should MySQL tables use it?

IntermediateConceptMySQL
Answer

Short answer

utf8mb4 is MySQL's real, full UTF-8 character set — it supports every Unicode character, including emojis and many Asian characters. MySQL's old utf8 (actually utf8mb3) only supports up to 3 bytes per character and fails or corrupts 4-byte characters like 😀. Use utf8mb4 everywhere (it's the default in MySQL 8).

The bug you'll see with old utf8

ERROR 1366 (HY000): Incorrect string value: '\xF0\x9F\x98\x80' for column 'comment'

Set it properly

CREATE DATABASE shop CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
ALTER TABLE reviews CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
SHOW VARIABLES LIKE 'character_set%';

Also set the connection charset (?characterEncoding=utf8 / charset=utf8mb4 in the client/driver).

Migration gotcha

Moving from MySQL 5.7 (latin1/utf8 defaults) to 8.0 or RDS: mismatched charsets and collations cause Illegal mix of collations errors in joins — standardise before migrating.

What to say in the interview

"utf8mb4 is full 4-byte UTF-8; MySQL's legacy utf8 is 3-byte and breaks on emojis. I standardise databases, tables and client connections on utf8mb4, which is the default in MySQL 8, and check collations during migrations."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: MySQL basics

More on MySQL