Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysqldump with utf8 can not export the right emojis string

I am using MySQL 5.5.29, utf8mb4 charset, there is a table user containing a field nickname with value hex F09F988EF09F988E that translates to the 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/'
like image 322
user3036278 Avatar asked Nov 26 '13 12:11

user3036278


People also ask

Is Mysqldump capable of exporting a database?

There are three ways in which the mysqldump tool can be used: First, it can be used to export specific tables in a MySQL database. Second, it can be used to export databases. Third, it can be used to export an entire MySQL server.

How do I search for Emojis in MySQL?

You use utf8mb4_unicode_ci for your columns, so the check is case insensitive. If you use utf8mb4_bin instead, then the emoji šŸŒ® and šŸŒ¶ are correctly identified as different letters. With WEIGHT_STRING you can get the values that are use for sorting and comparison for the input string.


1 Answers

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)
like image 92
user3036278 Avatar answered Nov 02 '22 20:11

user3036278