Vlad Markushin
Vlad Markushin

Reputation: 463

Emoji support in MySQL

I read a bunch of articles on the topic of how to implement emoji support in MySQL, but nothing does not work.

my.cnf:

[client]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
character-set-client-handshake = FALSE
[mysql]
default-character-set = utf8mb4

test:

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 |
+--------------------------+--------------------+

I've tried both MyISAM and InnoDB.

What is wrong with this?

Upvotes: 1

Views: 2408

Answers (1)

wchiquito
wchiquito

Reputation: 16551

Try:

mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.7.11    |
+-----------+
1 row in set (0.00 sec)

mysql> SET NAMES utf8mb4;
Query OK, 0 rows affected (0.00 sec)

mysql> DROP TABLE IF EXISTS `tbl_test`;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE IF NOT EXISTS `tbl_test` (
    ->   `message` VARCHAR(100) DEFAULT NULL
    -> ) DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO `tbl_test` (`message`)
    -> VALUES ('Hello 🐬');
Query OK, 1 row affected (0.00 sec)

mysql> SELECT `message`
    -> FROM `tbl_test`;
+------------+
| message    |
+------------+
| Hello 🐬     |
+------------+
1 row in set (0.00 sec)

See db-fiddle.

UPDATE

Using Workbench 6.3 Community:

Workbench 6.3 Community

Upvotes: 5

Related Questions