Analytic

Friday, January 13, 2012

Fixing double-encoded UTF-8 data in MySQL

When the data has been double-encoded, you will still have funny looking characters in the database.
Here is how to fix it, in two simple steps, using the mysqldump and mysql commands:

Source Database:

mysqldump -h DB_HOST -u DB_USER -p DB_PASSWORD --opt --quote-names \
--skip-set-charset --default-character-set=latin1 DB_NAME > DB_NAME-dump.sql

Target Database: mysql -h DB_HOST -u DB_USER -p DB_PASSWORD \
--default-character-set=utf8 DB_NAME < DB_NAME-dump.sql

No comments: