mySQLdb versus platform problem
John Nagle
nagle at animats.com
Sat Mar 17 01:42:12 EDT 2007
Robin Becker wrote:
> John Nagle wrote:
>
>> Try:
>>
>> db=MySQLdb.connect(host='appx',db='sc_0',user='user',passwd='secret',
>> use_unicode=True, charset = "utf8")
>>
>> The distinction is that "use_unicode" tells Python to convert to Unicode,
>> but Python doesn't know the MySQL table type. 'charset="utf8"' tells
>> MySQL to do the conversion to UTF8, which can be reliably converted
>> to Unicode.
>>
>> John Nagle
>>
>> .......
>
>
> OK that seems to help. However, my database has tables with different
> encodings. Does MySQLdb ignore the table encoding? That would be a bit
> lame.
MySQLdb, the client, doesn't know the table encoding. The
server end does.
> Also it still doesn't explain the different behaviours between unix &
> win32 (or perhaps different defaults are somehow magically decided upon).
The default encoding is an environment thing. It comes, somehow, from
the locale your system thinks it is in.
> -things were so much easier when bytes were bytes-ly yrs-
> Robin Becker
So convert the database to Unicode/UTF-8 and have everything
be consistent. MySQL 5 can do that dynamically with an ALTER
TABLE statement.
John Nagle
More information about the Python-list
mailing list