You are here

MySQL Character Encoding

I encountered a funky problem on this very site where certain characters in my news feeds were getting garbled in the database. I suspected it was a Unicode/UTF-8/etc problem, and upon exploration I discovered this suggestion. First backup the table(s) with the offending data:

$ mysqldump -uusername -ppassword --add-drop-table --default-character-set=latin1 database table > backup.sql

Then restore the table(s) with the following command:

mysql -uusername -ppassword --default-character-set=utf8 database < backup.sql

This in itself didn't completely solve the problem. When I examined the backup.sql file, I discovered it contained the following line:

/*!40101 SET NAMES latin1 */;

I commented that out and restored the table again (using the mysql command above). Voila, ça marche!