Menu

Defining character set with 4.1

Help
micu
2005-02-16
2012-09-19
  • micu

    micu - 2005-02-16

    I found problem with proper defining default client/connection character set used within MySQLdb 1.2.0 and MySQL 4.1.19. The settings I put in my.ini doesn't seem to work (although mysql.exe properly recognizes them).
    The workaround I found is to manually describe path to the my.ini file while using 'connect' function, but it doesn't satisfy me at all. So the question is where the MySQLdb module seeks for default my.ini file?

     
    • Andy Dustman

      Andy Dustman - 2005-02-17

      The mysql command line client, as far as I know, reads ~/.my.cnf automatically. It might also read the system-wide my.cnf as well; check the documentation. The C API does not do this on it's own, so MySQLdb does not do this either. Set read_default_file on connect() or subclass the connection object to do it automatically.

       
      • micu

        micu - 2005-02-17

        There is total mess with config files. Newest MySQL uses by default it's own directory (eg. c:\mysql\my.ini), but allows defining the path to the file during service startup. This (default) location is by no means accepted by mysql.exe client, which looks for my.cnf or my.ini file in c:\ or c:\windows directory. Neither of these locations is accepted by MySQLdb, although it implicitly uses mysql_options() functions with states:

        "MYSQL_READ_DEFAULT_FILE Read options from the named option file instead of from my.cnf."

        Therefore I believe it should be something like 'default' my.cnf file location, but after spending couple of hours trying to find it, I think I give up. This is really strange because MySQL 4.0+MySQLdb 1.0 worked perfectly ok.
        Of course using read_default_file or subclassing connect class is simple solution, especially with new projects, but due to its incompability it collides with many other efforts, ie. object-relational mappers like SQLObject with it's nice URI's.

         
        • Andy Dustman

          Andy Dustman - 2005-02-17

          Oh well. Location of that file is platform-dependent, as far as I know, but you can patch MySQLdb to do it with one line of code. In MySQLdb.connections.Connection.init, add a line like this:

          kwargs2['read_default_file'] = "/wherever/the/it/is/my.cnf"
          

          or since you have Windows:

          kwargs2['read_default_file'] = r"c:\mysql\my.ini"
          

          http://dev.mysql.com/doc/mysql/en/mysql-options.html

          Personally I think the docs are wrong or misleading. You might want to put in a comment asking for clarification. Maybe it only reads from the default file if read_default_group is set; my testing seems to support this.

           

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.