Recently, an old project of the company needed to support emoji expressions. At first, I thought it would be just a matter of modifying the table fields of the database, but unexpectedly it caused a series of problems. Summarize it here as a reminder.
01 MySQL Character setSettings
##System variables:
character_set_client: Character set used by client source data
character_set_connection: Connection layer character set
character_set_results: Query result character set
character_set_database: Default character set of the currently selected database
character_set_system: System metadata (field name, etc.) character set
character_set_client to
character_set_connection;
character_set_connection to the internal operating character set, which is determined as follows:
character_set_server setting value.
character_set_results, in response to the request.
Configuration file my.cnf
default-character-set: Set mysql command The default character set for line connectioncharacter-set-server: Set the system's internal operating character set (i.e. the character_set_server mentioned above)
collation_server: Set the system's default character set sorting
, this is just required
,character_set_connection
, The character sets of character_set_results
are the same, and they are all utf8mb4
(these three parameters are all utf8mb4
by default. If not, emoji expressions cannot be realized. For reasons, please refer to Character Set Conversion process).
also needs to be utf8mb4
are not that important, but it is best to keep them consistentThere are indeed many pitfalls in TP, stay away from TP
The above is the detailed content of Detailed explanation of MySQL character set issues (picture). For more information, please follow other related articles on the PHP Chinese website!