Many people think it’s as simple as doing a mysqldump->sed->mysql command (or clicking Change->Collation in PhpMyAdmin) but that only changes the encoding for NEW data, while leaving the old data intact and possibly coming out dirty.
Luckily there is a really handy tool called iconv that does character set conversions.
So to migrate character encodings properly in a MySQL database use a command like:
$ mysqldump -u USERNAME -pPASSWORD DATABASE |
replace CHARSET=latin1 CHARSET=utf8 |
iconv -f latin1 -t utf8 |
mysql -u USERNAME -pPASSWORD DATABASE
replace CHARSET=latin1 CHARSET=utf8 |
iconv -f latin1 -t utf8 |
mysql -u USERNAME -pPASSWORD DATABASE
Where USERNAME, PASSWORD & DATABASE should be replaced with your username, password and database, of course.

Leave a Reply