Menu

Default mysql socket location?

Brian Cole
2006-01-25
2012-09-19
  • Brian Cole

    Brian Cole - 2006-01-25

    I know you can use the "unix_socket=" argument to point MySQLdb to the right place, but what I'm wondering is how MySQLdb decides what is the 'default' location for a socket? Does it try to parse any config files, etc?

    I'm perused the source and can't seem to find it for myself.

    Thanks
    -Brian

     
    • Andy Dustman

      Andy Dustman - 2006-01-25

      It's a compile-time option for MySQL, but I'm pretty sure it can also appear in my.cnf files.

      http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html
      http://dev.mysql.com/doc/refman/5.0/en/mysql-real-connect.html

      In particular:

      """By using mysql_options() the MySQL library reads the [client] and [your_prog_name] sections in the my.cnf file which ensures that your program works, even if someone has set up MySQL in some non-standard way."""

      Note, however, that _mysql (the low-level part of MySQLdb) does not call mysql_options() unless one of these parameters has been set: connect_timeout, named_pipe, compress, init_command, read_default_file, read_default_group, local_infile. That can probably be a bit confusing, and I don't think it was well-documented when I wrote that code about 5 years ago.

       
      • Brian Cole

        Brian Cole - 2006-01-25

        Why not throw a try/except around the connection and call mysql_options whenever the connection fails? If that attempt fails just die out appropriately.

        -Brian

         
        • Andy Dustman

          Andy Dustman - 2006-01-26

          For one, the only place mysql_options() is called is in C code, so there's no try ... except. For two, You're supposed to call mysql_options() before the connection is opened with mysql_real_connect(), which is why it's done in the initialization for the object.

           

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.