drawkcaB | Backward Compatible logo

rants and tips about software

Weird characters in restored MySQL database

I’m moving one of my websites to a different server, and part of it is
moving a MySQL database. It has different international users and a
lot of data in UTF-8 character set which does not fit into default ISO
8859-1 space. Using phpMyAdmin (no other way on old host) I backed up
the entire database into .sql file encoded with UTF8, but when I
imported it from the command line using:

mysql -p mydatabase

however, all the non-ISO8859_1 characters got busted and don’t display
correctly. Solution is to supply the connection character set, so all
data is transferred as UTF-8:

mysql -p --default_character_set utf8  mydatabase < dump.sql
Milan Babuškov, 2009-11-16
Copyright © Milan Babu┼íkov 2006-2014