(I) Preface
In order to cope with opportunities and challenges of the wireless Internet, and to avoid problems caused by emoji,
We recommend that you use the utf8mb4 character set in advance for MySQL databases involving wireless connection.
This must be a key point of technology selection in the mobile Internet industry.
(Ii) Restrictions
Required> = MySQL 5.5.3 and slave database must also be 5.5. Earlier versions do not support this character set or duplicate error.
(Iii) Brief steps
The following is a configuration step that has not been upgraded to 5.5.3:
① Back up the database
② Upgrade MySQL server to v5.5.3 +
③ Modify the character set of database, table, and column
# For each database: Alter database database_name Character Set = utf8mb4 collate = collate; # for each table: alter table table_name convert to Character Set utf8mb4 collate utf8mb4_unicode_ci; # for each column: alter table table_name change column_name varchar (191) Character Set utf8mb4 collate utf8mb4_unicode_ci; # (Don't blindly copy-paste this! The exact statement depends on the column type, maximum length, and other properties. The above line is just an example for a 'varchar 'column .)
④ Modify my. CNF
[client]default-character-set = utf8mb4[mysql]default-character-set = utf8mb4[mysqld]character-set-client-handshake = FALSEcharacter-set-server = utf8mb4collation-server = utf8mb4_unicode_ciinit_connect='SET NAMES utf8mb4'
⑤ Restart MySQL server and check Character Set
mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';+--------------------------+--------------------+| Variable_name | Value |+--------------------------+--------------------+| character_set_client | utf8mb4 || character_set_connection | utf8mb4 || character_set_database | utf8mb4 || character_set_filesystem | binary || character_set_results | utf8mb4 || character_set_server | utf8mb4 || character_set_system | utf8 || collation_connection | utf8mb4_unicode_ci || collation_database | utf8mb4_unicode_ci || collation_server | utf8mb4_unicode_ci |+--------------------------+--------------------+ rows in set (0.00 sec)