utf8 data with mysql latin1 database

43 views
Skip to first unread message

Aljosa Mohorovic

unread,
Mar 14, 2008, 6:18:02 AM3/14/08
to Django users
i've accidentally used mysql latin1 database/tables/columns instead
utf8 and stored utf8 data in database with latin1 encoding.
i've tried to convert database to utf8 database using all kind of
instructions i've found but nothing worked.
most non-ascii chars are wrong or lost when converting to utf8
database.

anybody knows what i could do? i'm asking this here because i assume
that this could happen to anybody else using django and syncdb to
create tables.

Aljosa

p.s.
mysql server version: 5.0.22

Matthias Kestenholz

unread,
Mar 14, 2008, 6:26:58 AM3/14/08
to django...@googlegroups.com
Hi,

the following steps worked (almost always) for me:

1.
$ mysqldump your_db > dump.sql

2.
drop and re-create database with the correct encoding

3.
$ recode utf8..latin1 dump.sql
(The utf8 is converted from latin1 to utf8 when dumping, so you have to
convert the doubly-utf8-encoded string once back to latin1 to get your
utf8 content back)

4.
$ mysql your_db < dump.sql


Maybe there is an easier way?

--
http://spinlock.ch/blog/

Malcolm Tredinnick

unread,
Mar 14, 2008, 6:28:55 AM3/14/08
to django...@googlegroups.com

On Fri, 2008-03-14 at 03:18 -0700, Aljosa Mohorovic wrote:

I would have guessed that something like this would work:

http://tlug.dnho.net/?q=node/276

Essentially, you need to extract the data out in latin1 format via some
kind of dumping operation. Then recreate the tables as utf8 tables and
then reload data, telling the database this time that it's really utf8
(it doesn't know you called it latin1 last time).

Malcolm

--
The early bird may get the worm, but the second mouse gets the cheese.
http://www.pointy-stick.com/blog/

Reply all
Reply to author
Forward
0 new messages