mysqldump with utf8 can not export the right emojis string

匿名 (未验证) 提交于 2019-12-03 08:44:33

问题:

mysql 5.5.29, utf8mb4 charset, there is a table user containing a field nickname with value hex F09F988EF09F988E that is emojis ??.

Now open mysql console, and execute:



set names utf8mb4;
select nickname, hex(nickname) from user;


nickname | hex(nickname)
?? | F09F988EF09F988E


and then execute mysqldump --default-character-set=utf8 -utest -ptest test_dev user > user.sql

check the user.sql and find the nickname display ?? which hex string is 3f

so, how can mysqldump with utf8 export the right emojis string?


btw, the database charset envionments configured as follow: show variables like 'character_set_%': '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', '/data/mysql/share/charsets/'

回答1:

Thanks Danack!
Thru specifying utf8mb4 charset and upgrading mysqldump version to 5.5.3+, mysqldump & mysql work well for 4 bytes emojis.

[tomcat@localhost ~]$ mysqldump --default-character-set=utf8mb4 -utest -ptest test_dev user > user.sql

If it shows an error like:

mysqldump: Character set 'utf8mb4' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file

check your mysqldump version (mysqldump --version)

[tomcat@localhost ~]$ mysqldump --version mysqldump  Ver 10.11 Distrib 5.0.95, for redhat-linux-gnu (x86_64)

It works after upgrading mysqldump to 5.5.33.

[tomcat@localhost ~]$ mysqldump --version mysqldump  Ver 10.13 Distrib 5.5.33, for Linux (x86_64)


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!