I'm using the Ansible mysql_db module to create a sql dump file of a database on a remote server. I'm then downloading this dump file to import into a local database that has a different name.
My issue is that the dump file that the mysql_db module creates is prefixed with the CREATE DATABASE and USE commands. E.g.:
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `remote_db_name` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `remote_db_name`;
This is causing issues as, when I try to import this dump into my local database (that has a different name), it's creating a whole new database locally and importing into that instead.
Are there any options you can pass to the Ansible mysql_db module to prevent it adding the CREATE DATABASE and USE commands to the dump file?
Here is the line in my Ansible playbook that creates the sql dump file:
mysql_db: state=dump name={{ db_name }} login_user={{ db_user }} login_password={{ db_password }} target=/var/www/{{ domain_name }}/db_backups/{{ db_name }}_{{ dumpdate }}.sql
Remote server is running Ubuntu 18.04 with MySQL Ver 14.14 Distrib 5.7.28 if that makes any difference.
Transforming comment as answer upon OP's request
There is an option you can pass to mysqldump (i.e. --no-create-db) but the ansible module does not seem to support it.
So at time of writing this answer (6th of December 2019) you either need to:
mysqldump
yourself through command or shellIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With