Enable MySQL 5.6 to support Emoji expressions
Let MySQL support Emoji expressions. We recommend that you use the utf8mb4 character set in advance for MySQL databases involving wireless connections.
MySQL 5.6
1 solution: Convert Mysql encoding from utf8 to utf8mb4.
Required> = MySQL 5.5.3 and slave database must also be 5.5. Earlier versions do not support this character set or duplicate error.
2 Add the my. cnf File
[Mysqld]
Character-set-server = utf8mb4
Collation-server = utf8mb4_unicode_ci
Init_connect = 'set NAMES utf8mb4'
3. Modify the character set of the database and table fields to be added.
Modify the database character set:
Alter database database_name character set = utf8mb4 COLLATE = utf8mb4_unicode_ci;
Modify the character set of a table:
Alter table table_name convert to character set utf8mb4 COLLATE utf8mb4_unicode_ci;
Modify the character set of a field:
Alter table table_name CHANGE column_name VARCHAR (191) character set utf8mb4 COLLATE utf8mb4_unicode_ci;
If you only need to modify the character set of a field
4. If none of the above statements can be modified, query the SQL statement.
Mysql> show variables like '% SQL _mode % ';
+ --------------- + ---------------------------------------------- +
| Variable_name | Value |
+ --------------- + ---------------------------------------------- +
| SQL _mode | STRICT_TRANS_TABLES, NO_ENGINE_SUBSTITUTION |
+ --------------- + ---------------------------------------------- +
1 row in set (0.00 sec)
If the above result is returned, congratulations, you cannot store it.
Set the SQL _mod mode (note that you need to exit the console after modification, or you still cannot see the effect.
This configuration does not take effect when I write my. cnf to restart the server. If you want to ask why please go to the mysql Consulting Group)
Mysql> set global SQL _mode = 'no _ ENGINE_SUBSTITUTION ';
Mysql> show variables like '% SQL _mode % ';
+ --------------- + ------------------------ +
| Variable_name | Value |
+ --------------- + ------------------------ +
| SQL _mode | NO_ENGINE_SUBSTITUTION |
+ --------------- + ------------------------ +
1 row in set (0.00 sec)
6. After completing these steps, let MySQL support Emoji expressions.
This article permanently updates the link address: