Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump SQL with use database since 2.9 #65351

Open
platypus-geek opened this issue Nov 28, 2019 · 8 comments · May be fixed by #65723
Open

Dump SQL with use database since 2.9 #65351

platypus-geek opened this issue Nov 28, 2019 · 8 comments · May be fixed by #65723

Comments

@platypus-geek
Copy link

@platypus-geek platypus-geek commented Nov 28, 2019

SUMMARY

Since 2.9 mysql_db dump create dump with create database and use instruction.
Is that possible to add an option for using --no-create-db with a dump ?

ISSUE TYPE
  • Feature Idea
  • Bug Report
COMPONENT NAME

mysql_db

@ansibot

This comment has been minimized.

Copy link
Contributor

@ansibot ansibot commented Nov 28, 2019

Files identified in the description:
None

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot

This comment has been minimized.

Copy link
Contributor

@ansibot ansibot commented Nov 28, 2019

@platypus-geek: Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.

Here are the items we could not find in your description:

  • component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

click here for bot help

@ansibot

This comment has been minimized.

Copy link
Contributor

@ansibot ansibot commented Nov 28, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@Akasurde

This comment has been minimized.

Copy link
Member

@Akasurde Akasurde commented Nov 29, 2019

@pratikgadiya12 Since you recently worked on this feature, can you please comment on this ? Thanks.

@ansibot ansibot removed the needs_triage label Nov 29, 2019
@bmalynovytch

This comment has been minimized.

Copy link
Contributor

@bmalynovytch bmalynovytch commented Nov 29, 2019

+label easyfix

@ansibot ansibot added the easyfix label Nov 29, 2019
@mlerota

This comment has been minimized.

Copy link

@mlerota mlerota commented Dec 2, 2019

Hi guys. I just want to add one more comment how this change is breaking a lot of deployments.
Currently we are using mysql_db module for dump and import. So we are dumping one database and importing it to another. If the dumped file now has a USE` `db_name`; statement, the import module will ignore the database name and it will import the db to the name in this USE statement. So back to itself.

This doesn't work any more:

- name: Dump the database
  mysql_db:
    state: dump
    name: database1
    login_user: "{{ db_user }}"
    login_host: "{{ db_host }}"
    login_password: "{{ db_pass }}"
    single_transaction: yes
    target: "{{ dump_file }}"

- name: Import the database
  mysql_db:
    state: import
    name: database2
    login_user: "{{ db_user }}"
    login_host: "{{ db_host }}"
    login_password: "{{ db_pass }}"
    target: "{{ dump_file }}"
  register: dbimport_try
  retries: 3
  delay: 5
  until: dbimport_try is not failed

With this bug, import to databse2 will never be executed.
I think the best way would be to revert and not use USE statement in dumps. Otherwise you would have to delete this part from dump somehow before every import. Or use option in the dump module to mitigate this.

Nice regards,
Marko

@fnkr

This comment has been minimized.

Copy link

@fnkr fnkr commented Feb 11, 2020

We encountered the same issue. IMO Ansible should not use --databases unless multiple databases are specified (this is the pre-Ansible-2.9 behavior). Maybe add an option to control the use of --databases. Adding --no-create-db as an option would not fix this as the dump would still contain a USE statement.

This is our workaround for now:

# https://github.com/ansible/ansible/issues/65351
- name: WORKAROUND - Remove "CREATE DATABASE" and "USE" statements from SQL dump
  command: sed -i -e '/^CREATE DATABASE /d' -e '/^USE /d' /tmp/dump.sql
@ansibot ansibot added the has_pr label Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants
You can’t perform that action at this time.