开发者

Telling MySQL connection to use UTF-8 with Django

I've uploaded some data to a MySQL (5.5.15 for osx10.6) database using UTF8 encoding, though for some reason I had to specify its encoding as latin1 when I LOADed it.

I reckon this part is good because when I write to an OUTFILE, my unicode 'nu' characters come out OK in a terminal and in Vim.

However, when I look at them within a MySQL session, and when I try to edit the fields from Django admin, I get mangled characters (latin1?).

So, my question is: how to I tell a MySQL client and (especially) Django to read my database as UTF-8, the way it oughta?

At the command line, I tried

--default_character_set=utf8 

and also

'SET NAMES UTF8;'

at the MySQL prompt, but they do not work.

When I look at 开发者_运维知识库VARIABLES LIKE 'char%', they're all set to utf8 apart from character_set_server which is latin1. If I set it to utf8.... that doesn't work either.

I'd be grateful if someone could give me some pointers here, especially about how to configure Django to talk to my database properly.

Thanks!


Add in your .cnf:

[mysqld]
character-set-server = utf8
collation-server     = utf8_general_ci
skip-character-set-client-handshake
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜