Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preserve UTF8mb4 data with mysqldump?

I'm using mysqldump to dump my database that contains UTF8MB4 columns with UTF8MB4 data. When I import this .sql file into a new database with UTF8MB4 support, all UTF8MB4 characters are converted into ????. Anybody got a clue about how to make MySQL and import work with UTF8MB4?

like image 808
Vidar Vestnes Avatar asked Jan 21 '15 07:01

Vidar Vestnes


People also ask

How do I change utf8mb4 to utf8?

To solve the problem open the exported SQL file, search and replace the utf8mb4 with utf8 , after that search and replace the utf8mb4_unicode_520_ci with utf8_general_ci . Save the file and import it into your database. After that, change the wp-config. php charset option to utf8 , and the magic starts.

What is the difference between utf8 and utf8mb4?

The difference between utf8 and utf8mb4 is that the former can only store 3 byte characters, while the latter can store 4 byte characters. In Unicode terms, utf8 can only store characters in the Basic Multilingual Plane, while utf8mb4 can store any Unicode character.

Does Mysqldump compress data?

mysqldump ( mysqldump -C ) also supports compressed communication which could perhaps make things transfer faster over the network.

Does Mysqldump include indexes?

No, it does not export indexes. Indexes are rebuilt upon loading the mysqldump back into mysql.


1 Answers

You should specify the character set with --default-character-set=utf8mb4 option when using mysqldump.

$ mysqldump --default-character-set=utf8mb4 -uusername -p database > dump.sql
like image 76
Henridv Avatar answered Sep 23 '22 07:09

Henridv