~hruske Hruške, jabuke, jablane, čežane. » Blog Archive » Fixing MySQL encoding problems
Home Contact Sitemap

Hruške, jabuke, jablane, čežane.

Ste se gdaj vprašali, zakaj Najboljšega soseda nikoli ni doma, ko pridete na obisk?

Fixing MySQL encoding problems

Posted on Oktober 13th, 2008 in dovhcajt |

Dialects of :w:en:Slovenian language, after Ra...Image via WikipediaKiberpipa‘s web page runs on MySQL, that famous and far too popular open source database, that forces developers to encounter all kinds of funny errors. Well, encoding problems are one of them.

Slovenian language works okay with character set latin2, but MySQL doesn’t really check what encoding is database using, so the database is stored in latin1, and application works using latin2. What MySQL does here, is store the data it gets using latin1 encoding, not knowing the data is already encoded using latin2. Fun.

So, moving to UTF-8 should solve this problems, but unfortunately you can’t just do a dump using UTF-8 encoding, because MySQL breaks your data. You need to dump using the encoding you have the database stored in, then convert using iconv to get an UTF-8 encoded dump. As a last step, you need to change table encodings accordingly.

Ok, enough talk. All the above translates to:

mysqldump --opt --default-character-set=latin1 -u root -p database_name | iconv -f latin2 -t utf-8 | sed -e 's/CHARSET=latin1/CHARSET=utf-8/g' > database_dump.sql

Reblog this post [with Zemanta]

Comments are closed.

Komentarji so izklopljeni