Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#30636 closed Bug (fixed)

mysqldump crash when --defaults-file is not given before other options.

Reported by: Yann Sionneau Owned by: Yann Sionneau
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: mysqldump
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Yann Sionneau)

What happens?
Running tests gives:
Creating test database for alias 'default'...
Cloning test database for alias 'default'...
mysqldump: unknown variable 'defaults-file=/var/lib/jenkins/workspace/Pytition_master/my.cnf'
And then every test fails with 'E' (error).

How to reproduce?
1/ Configure your database like this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'OPTIONS': {
            'read_default_file': '/path/to/my.cnf', # file with credentials and db name
        },
    }
}

2/ run tests with "manage.py test --parallel 2 appname"
The important here is "--parallel 2" (or more than 2)

Explanations?

This happens because Django tries to clone the database using mysqldump: https://github.com/django/django/blob/master/django/db/backends/mysql/creation.py#L60
In my case I've printed the arguments, it gives:

dump_cmd: ['mysqldump', '--routines', '--events', '--defaults-file=/var/lib/jenkins/workspace/Pytition_master/my.cnf', 'test_']
load_cmd: ['mysql', '--defaults-file=/var/lib/jenkins/workspace/Pytition_master/my.cnf', 'test__1']
mysqldump: unknown variable 'defaults-file=/var/lib/jenkins/workspace/Pytition_master/my.cnf'

However, it seems that, even if this is undocumented in mysqldump's man page, it does only support --defaults-file parameter when in first position.

See the Note on this StackOverflow answer: https://stackoverflow.com/questions/10725209/specifying-separate-config-file-on-mysqldump-command-line

Proposed solution:
Test if read_default_file is in settings, and in this case put it as first argument to mysqldump

Change History (11)

comment:1 by Yann Sionneau, 5 years ago

Description: modified (diff)

comment:2 by Yann Sionneau, 5 years ago

Description: modified (diff)

comment:3 by Yann Sionneau, 5 years ago

Easy pickings: set

comment:4 by Yann Sionneau, 5 years ago

It seems that the same requirement exists for "mariabackup" (the equivalent tool to mysqldump for MariaDB).
See https://mariadb.com/kb/en/library/mariabackup-overview/

The following options relate to how MariaDB command-line tools handles option files. They must be given as the first argument on the command-line:

Also, a confirmation in MySQL documentation that "defaults-file" must be given before other options: https://dev.mysql.com/doc/refman/5.5/en/option-file-options.html

Last edited 5 years ago by Yann Sionneau (previous) (diff)

comment:5 by Yann Sionneau, 5 years ago

Has patch: set

I propose this patch to fix the issue: https://github.com/django/django/pull/11567

comment:6 by Yann Sionneau, 5 years ago

Owner: changed from nobody to Yann Sionneau
Status: newassigned

comment:7 by Mariusz Felisiak, 5 years ago

Easy pickings: unset
Keywords: mysqldump added
Summary: mysqldump errors out with "unknown variable" when --parallel and --defaults-filemysqldump crash when --defaults-file is not given before other options.
Triage Stage: UnreviewedAccepted

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In e47b8293:

Fixed #30636 -- Fixed options ordering when cloning test database on MySQL.

--defaults-file must be given before other options.

comment:9 by Floréal Cabanettes, 4 years ago

I have still the problem with django 2.2.11, is the problem only solved on django 3.0?

comment:10 by Floréal Cabanettes, 4 years ago

Effectively, the commit is only for 3.0. If I apply change to my 2.2.11 django it works. Is it possible to include this fix officially in the LTS 2.2 series?

comment:11 by Simon Charette, 4 years ago

This commit won't be backported to 2.2.x per our backporting policy.

Note: See TracTickets for help on using tickets.
Back to Top