Ticket #5120 (closed enhancement: fixed)
Opened 5 years ago
Last modified 7 weeks ago
[PATCH] mysql_backend should parse parameters
| Reported by: | anonymous | Owned by: | thijstriemstra |
|---|---|---|---|
| Priority: | high | Milestone: | 0.13 |
| Component: | database backend | Version: | devel |
| Severity: | major | Keywords: | mysql patch bitesized |
| Cc: | dekimsey@… | ||
| Release Notes: |
mysql_backend passes any additonal connection parameters to the database |
||
| API Changes: | |||
Description
Currently, mysql_backend.py only passes db, user, passwd, host, and port to MySQLdb. Any additional params are discarded.
This is particularly unfortunate (at least in my case) because a number of MySQL installs do not use the default socket location, yet:
mysql://user:password@domain:3306/database?unix_socket=path/to/socket
fails, even though the backend would easily accept it.
Attachments
Change History
comment:1 Changed 5 years ago by cboos
- Component changed from trac-admin to general
- Keywords mysql added
- Milestone changed from 0.12 to 0.10.5
- Owner changed from cmlenz to jonas
comment:2 follow-up: ↓ 7 Changed 4 years ago by dekimsey@…
Agreed, this is actually kind of important in my opinion as I'd really prefer not to have the mysql connect information stored inside the trac.ini file. The mysql library is able to read a configuration file instead.
I implemented a bit of a hack to get the read_default_file parameter to be passed into the connect call, I might upload a patch of it if I can figure out the correct way to pass the params hash properly to the connect sub by name. (I'm not very familiar with Python, I'm a Perl person :/)
--
Danny
comment:3 Changed 4 years ago by dekimsey@…
- Cc dekimsey@… added
The only issue I have run into so far in implementing this was that certain parameters cannot be left as None and must either be passed as something valid or not passed at all. Some trial and error and I've worked down which is which.
I simply push those with defined values onto the params hash and then pass that to the connect method. It works for me, I have not tested it with an older mysqldb library than the if block checks for.
--
Danny.
Changed 4 years ago by dekimsey@…
- Attachment mysql.cnf.hack.patch added
this is a patch to add parameter support to source:/trunk/trac/db/mysql_backend.py@6299
comment:4 Changed 3 years ago by cboos
- Keywords patch added
- Milestone changed from 0.10.6 to 0.11.6
comment:5 Changed 2 years ago by rblank
- Keywords bitesized added
Changed 14 months ago by thijstriemstra
- Attachment mysql-params-5120.patch added
patch against 0.12-stable r10371
comment:6 Changed 14 months ago by thijstriemstra
- Milestone changed from next-minor-0.12.x to 0.12.2
- Owner changed from jonas to thijstriemstra
- Status changed from new to assigned
- Summary changed from mysql_backend should parse parameters to [PATCH] mysql_backend should parse parameters
The attached patch passes in the params from the connection string, like unix_socket or use_unicode.
comment:7 in reply to: ↑ 2 Changed 14 months ago by thijstriemstra
- Component changed from general to database backend
- Priority changed from normal to high
- Severity changed from normal to major
Replying to dekimsey@…:
Agreed, this is actually kind of important in my opinion as I'd really prefer not to have the mysql connect information stored inside the trac.ini file. The mysql library is able to read a configuration file instead.
Agreed.
Changed 14 months ago by thijstriemstra
- Attachment mysql-params-5120-2.patch added
comment:8 Changed 14 months ago by thijstriemstra
Updated patch also passes in -S to mysqldump when doing a backup.
comment:9 Changed 14 months ago by rblank
I'm not sure it makes sense to pass all additional parameters to MySQLdb.connect() as keyword arguments, as the values will always be strings. I would prefer we explicitly process and pass in selected parameters.
What's the list of desired parameters? unix_socket is certainly useful, maybe also compress, named_pipe, init_command and read_default_file?
comment:10 follow-up: ↓ 12 Changed 14 months ago by rblank
#9949 asks for a way to connect to a MySQL server via SSL, and suggests using a ssl= parameter to specify the certificates and key.
Changed 14 months ago by thijstriemstra
- Attachment mysql-params-5120-3.patch added
against 0.12-stable r10394
comment:11 Changed 14 months ago by thijstriemstra
- Milestone changed from 0.12.2 to 0.13
- Type changed from defect to enhancement
Changed 14 months ago by thijstriemstra
- Attachment mysql-params-5120-4.patch added
against 0.13-trunk r10394
comment:12 in reply to: ↑ 10 Changed 14 months ago by thijstriemstra
Replying to rblank:
#9949 asks for a way to connect to a MySQL server via SSL, and suggests using a ssl= parameter to specify the certificates and key.
Attached a patch that's probably not pythonic but it gets the job done ;) Once this ticket is fixed it should be easy to add the additional options for SSL in #9949.
Tested with the following connection string:
mysql://admin:admin@localhost/trac?unix_socket=/tmp/mysql.sock&compress=1& init_command=SELECT COUNT(name) FROM wiki&read_default_file=/tmp/test.cnf&read_default_group=abc
Also updated the options to mysqldump. Wasn't able to test the named_pipe option because it's windows only. See MysqlDb docs.
comment:13 Changed 14 months ago by cboos
Looks good, however it lacks a bit of documentation: you should also list and explain the paramters in the doc string.
comment:14 follow-up: ↓ 15 Changed 13 months ago by rblank
- Resolution set to fixed
- Status changed from assigned to closed
Slightly simpler (and more pythonic) patch applied in [10407]. The changes were only in the form, not the function. The parameters are documented in the component docstring. I have also added a warning about unknown parameters.
Thijs, would you mind quickly checking that the arguments all work as expected?
comment:15 in reply to: ↑ 14 ; follow-up: ↓ 16 Changed 13 months ago by thijstriemstra
Replying to rblank:
Slightly simpler (and more pythonic) patch applied in [10407]. The changes were only in the form, not the function. The parameters are documented in the component docstring. I have also added a warning about unknown parameters.
Thijs, would you mind quickly checking that the arguments all work as expected?
Thanks for applying the patch, it all seems to work properly here.
comment:16 in reply to: ↑ 15 Changed 13 months ago by thijstriemstra
- Resolution fixed deleted
- Status changed from closed to reopened
Replying to thijstriemstra:
Thanks for applying the patch, it all seems to work properly here.
I forgot to test hotcopy :-/ It's now throwing:
$ trac-admin . hotcopy /tmp/tester Hotcopying /Users/thijstriemstra/Sites/projects/opensource/test3 to /tmp/tester ... Backing up database ... TracError: mysqldump failed: mysqldump: unknown variable 'defaults-file='
it seems mysqldump wants the defaults-file as it's first argument, which is the reason i didn't use db_params.iteritems() in the patch to ensure that defaults-file was the first param..
comment:17 Changed 13 months ago by rblank
- Resolution set to fixed
- Status changed from reopened to closed
Good catch! Fixed in [10410].
comment:18 follow-up: ↓ 19 Changed 13 months ago by thijstriemstra
comment:19 in reply to: ↑ 18 ; follow-up: ↓ 20 Changed 13 months ago by rblank
Replying to thijstriemstra:
This ticket isnt marked as closed in the trunk browser view for some reason..
That's because the link in the changeset is to a comment in the ticket (comment:16:ticket:5120), not to the ticket itself, and we seem to miss the strikeout in that case. Which can be considered as a bug.
comment:20 in reply to: ↑ 19 Changed 13 months ago by thijstriemstra
comment:21 Changed 7 weeks ago by al.willmer@…
- Release Notes modified (diff)



(moving to 0.10.x, along with other mysql related issues)