1. Modify MY.CNF
[client]default-character-set = utf8mb4[mysqld]collation-server = utf8mb4_unicode_cicharacter-set-server = utf8mb4
重启mysql,检查字符集是否已经更改,除了character_set_system
和character_set_filesystem
之外,其他的字符集都需要变成utf8mb4类型。
查看编码如下。
Mysql> Show variables like ' char% '; +--------------------------+------------------------------------------------ ------+| 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 | | Character_sets_dir | /usr/local/cellar/mysql/5.5.10/share/mysql/charsets/|+--------------------------+------------------------------------------------------+
2. In order to support a table created previously with UTF8 also supports emoji, you will also need to modify the previous table UTF8MB4 character set
alter table posts convert to character set utf8mb4 collate utf8mb4_unicode_ci;
3. If the insertion or failure after processing is complete, do not add the characterencoding parameter on the db URL parameter. When this parameter is not added, the default value is AutoDetect.
4.mysql support emoji with version constraints, it is recommended that MySQL upgrade to 5.5,mysql-connetion upgrade to 5.1.30.
MySQL support emoji