mysql emoji support

From http://blog.csdn.net/kinginblue/article/details/52445143

1. Change Mysql configuration file my.cnf (default location /etc/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'

2. Change existing database, table and column characters SET
    msql> ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
    msql> ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    msql> ALTER TABLE table_name CHANGE column column_name VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

    where database_name, table_name, column_name should be replaced with your corresponding database name, table name, column name. So is the length value of VARCHAR.

3. Restart Mysql and check the changed character set setting
    service mysql restart to
    check the character set setting:
    msql> 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)

4.使用 Druid 数据源配置,添加了一个配置:
    <property name="connectionInitSqls" value="set names utf8mb4;"/>

5.jdbc.url=jdbc:mysql://localhost:3306/demo?autoReconnect=true&failOverReadOnly=false
    去掉characterEncoding=utf8

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326127397&siteId=291194637