before you run the queries, run
set names utf8mb4;
Why?
In short.
First, Emoji usually takes four bytes, however, mysql's utf8
, an alias for for utf8mb3
, using one to three bytes(i.e., max byte three), which could not understand an Emoji char. As such, you see a '?' in your result. utf8mb4
can do the job since it requires a maximum of four bytes per multibyte character.
Second, set names utf8mb4
will set three session variable, e.g.,
SET character_set_client = utf8mb4;
SET character_set_results = utf8mb4;
SET character_set_connection = utf8mb4;
which will coordinate the barrier between server, client and results char set, so we can view the Emoji correctly.
For more information, you can find in the doc
https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-sets.html
https://dev.mysql.com/doc/refman/8.0/en/set-names.html