(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 = FALSE
Character-set-server = utf8mb4
Collation-server = utf8mb4_unicode_ci
Init_connect = 'set NAMES utf8mb4'
⑤ Restart MySQL Server and check Character Set
Mysql> show variables where Variable_name LIKE 'character \ _ set \ _ % 'OR Variable_name LIKE 'colation % ';
+ -------------------------- + -------------------- +
| 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)