I can successfully add emoji (i.e. utf8mb4 data) to tables using mysql using the terminal.
When my Python Flask website tries to send emoji to the same database tabl
I encountered almost the same problem recently, where accented characters were causing PHP json_encode() to complain about "malformed UTF8 characters."
Much to-ing and fro-ing in the documentation eventually led me to a paragraph at the bottom of the page 10.5 Character Set Configuration which states:
… when
character_set_systemdiffers fromcharacter_set_serverorcharacter_set_client, and you input characters manually (as database object identifiers, column values, or both), these may be displayed incorrectly in output from the client or the output itself may be formatted incorrectly.
In fact, character_set_system defaults to utf8 while character_set_server defaults to latin1 — I dare not speculate why.
My solution was to explicitly set character_set_server = utf8 (it defaults to latin1) and collation_server = utf8_general_ci (it defaults to latin1_swedish_ci) in the [mysqld] section of my my.cnf configuration file and then restart the service. The fact that these settings differed from the corresponding *_system settings apparently was the cause of my problem.
Some experimentation has confirmed that character_set_system must be utf8 or the server won't start. The documentation says that character_set_database can be set differently from character_set_server, but I'm not currently equipped to test the effects of this.