How to export/import MySQL database with exact character set?

mysqldump -uUSERNAME -pPASSWORD --default-character-set=utf8 DATABASE > backup.sql

When you import backup into an empty MySQL database, you can set the exact character set for the data that will be inserted. To do this, use the following command:

mysql -uUSERNAME -pPASSWORD --default-character-set=utf8 DATABASE < backup.sql

Replace –default-character-set=utf8 with the charset used for the creation of the backup.sql file. This will ensure that your data is inserted correctly.

character-set UTF8 vs UTF8MB4

MySQL utf8 is a propiatary standard from MySQL which does not reflect the real utf-8 standard. It uses only max. 3 bytes for a character. If you want to use real utf8 in your database you should use utf8mb4.

source: siteground.com, hydroxi.de

Leave a Reply

Your email address will not be published. Required fields are marked *