MySQL only storing some Emojis in text field when using UTF8MB4

时间:2016-10-20 18:39:36

标签: mysql utf-8

We have a project where we're storing Facebook and Twitter posts in a Mysql database, as first almost all Emojis were being stored as ?. We've since gone ahead and made some configuration changes to the database server, and since then we're starting to see more Emojis saving and appearing correctly, however some Emojis are still showing as ?, sadly I'm not sure which ones they are. I know one of them was a basket ball.

When I execute the following commend on MySQL;

SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%'
                  OR Variable_name LIKE 'collation%';

I see the following settings;

character_set_client     = utf8
character_set_connection = utf8
character_set_database   = utf8mb4
character_set_filesystem = binary
character_set_results    = utf8
character_set_server     = utf8mb4
character_set_system     = utf8
collation_connection     = utf8_general_ci
collation_database       = utf8mb4_unicode_ci
collation_server         = utf8mb4_unicode_ci

Our database server is hosted with Rackspace, we've asked them to set up the following configuration;

[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'

I've tested output from the database using a number of clients, PHP, Java and MySQL Workbench.

I'm at a loss now as to why some Emojis are not saving, and I've followed as much advice as I can find on the web.

1 个答案:

答案 0 :(得分:0)

character_set_client / connection / results = utf8 - 这三个由SET NAMES更改。您列出的内容似乎是在SET NAMES执行之前。

如果您以root进行连接,则init-connect不会被执行;也许这就是为什么你没有看到它。

为所有申请工作建立非SUPER用户;这样就会执行init-connect