Menu

Anyone tried utf8? I cannot get it to work...

Help
2005-03-28
2012-09-19
  • Alberto Mardegan

    Hi all! I can use UTF-8 with the mysql client, but not with Python+MySQLdb. My Mysql version is 4.1.10a (debian unstable), and MySQLdb is 1.2.0-4.
    The problem is this: the ~/.my.cnf file is

    ========
    [client]
    default-character-set=utf8
    ========

    and the program is:

    ========
    import MySQLdb as sql
    db = sql.connect(read_default_file="~/.my.cnf", host="localhost", user="mardy", passwd="", use_unicode=True)
    ========

    On the "connect" line, I get this error:

    ========
    Character set 'utf8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index' file
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "/usr/lib/python2.3/site-packages/MySQLdb/init.py", line 66, in Connect
    return Connection(*args, kwargs)
    File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 134, in init
    super(Connection, self).init(*args,
    kwargs2)
    _mysql_exceptions.OperationalError: (2019, "Can't initialize character set utf8 (path: /usr/share/mysql/charsets/)")
    ========

    I really need utf-8 support, because I'm going to insert some cyrillic text in the database.
    Can you please test my configuration, and tell me what happens to you? I just want to know what's wrong.

    TIA!

     
    • Alberto Mardegan

      You are right: I recompiled the module from the sources, and now it works! Thanks! :-)

       
      • Andy Dustman

        Andy Dustman - 2005-03-28

        It's an odd mistake to make, since MySQL-4.1 is supposed to use utf8 for the privilege tables; not having utf8 available would seem to break it entirely if mysql_fix_privilege_tables were run.

         
    • Andy Dustman

      Andy Dustman - 2005-03-28

      I suspect the problem is with your debian packaging of MySQL-4.1.10a, based on the error messages. On the Gentoo Linux box I have available at the moment, /usr/share/mysql/charsets/Index.xml has this section:

      <charset name="utf8">
      <family>Unicode</family>
      <description>UTF-8 Unicode</description>
      <alias>utf-8</alias>
      <collation name="utf8_general_ci" id="33">
      <flag>primary</flag>
      <flag>compiled</flag>
      </collation>
      <collation name="utf8_bin" id="83">
      <flag>binary</flag>
      <flag>compiled</flag>
      </collation>
      </charset>

      Note that it has <flag>compiled</flag>, which I assume means it doesn't need an external file in the same directory. Most of the other character sets are external files. It may be you have to adjust the Index.xml to include utf8.xml, if it exists.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.