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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"""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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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.
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
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.