ansible / ansible.builtin / v2.7.9 / module / mysql_db Add or remove MySQL databases from a remote host. | "added in version" 0.6 of ansible.builtin" Authors: Ansible Core Team preview | supported by communityansible.builtin.mysql_db (v2.7.9) — module
pip
Install with pip install ansible==2.7.9
Add or remove MySQL databases from a remote host.
- name: Create a new database with name 'bobdata' mysql_db: name: bobdata state: present
# Copy database dump file to remote host and restore it to database 'my_db' - name: Copy database dump file copy: src: dump.sql.bz2 dest: /tmp
- name: Restore database mysql_db: name: my_db state: import target: /tmp/dump.sql.bz2
- name: Dump all databases to hostname.sql mysql_db: state: dump name: all target: /tmp/{{ inventory_hostname }}.sql
- name: Import file.sql similar to mysql -u <username> -p <password> < hostname.sql mysql_db: state: import name: all target: /tmp/{{ inventory_hostname }}.sql
name: aliases: - db description: - name of the database to add or remove - name=all May only be provided if I(state) is C(dump) or C(import). - if name=all Works like --all-databases option for mysqldump (Added in 2.0) required: true quick: default: 'yes' description: - Option used for dumping large tables type: bool version_added: '2.1' version_added_collection: ansible.builtin state: choices: - present - absent - dump - import default: present description: - The database state target: description: - Location, on the remote host, of the dump file to read from or write to. Uncompressed SQL files (C(.sql)) as well as bzip2 (C(.bz2)), gzip (C(.gz)) and xz (Added in 2.0) compressed files are supported. ca_cert: aliases: - ssl_ca description: - The path to a Certificate Authority (CA) certificate. This option, if used, must specify the same certificate as used by the server. type: path encoding: description: - Encoding mode to use, examples include C(utf8) or C(latin1_swedish_ci) collation: description: - Collation mode (sorting). This only applies to new table/databases and does not update existing ones, this is a limitation of MySQL. client_key: aliases: - ssl_key description: - The path to the client private key. type: path login_host: default: localhost description: - Host running the database. - In some cases for local connections the I(login_unix_socket=/path/to/mysqld/socket), that is usually C(/var/run/mysqld/mysqld.sock), needs to be used instead of I(login_host=localhost). type: str login_port: default: 3306 description: - Port of the MySQL server. Requires I(login_host) be defined as other than localhost if login_port is used. type: int login_user: description: - The username used to authenticate with. type: str client_cert: aliases: - ssl_cert description: - The path to a client public key certificate. type: path config_file: default: ~/.my.cnf description: - Specify a config file from which user and password are to be read. type: path ignore_tables: default: [] description: - A list of table names that will be ignored in the dump of the form database_name.table_name required: false version_added: '2.7' version_added_collection: ansible.builtin check_hostname: description: - Whether to validate the server host name when an SSL connection is required. Corresponds to MySQL CLIs C(--ssl) switch. - Setting this to C(false) disables hostname verification. Use with caution. - Requires pymysql >= 0.7.11. - This optoin has no effect on MySQLdb. type: bool version_added: 1.1.0 version_added_collection: community.mysql login_password: description: - The password used to authenticate with. type: str connect_timeout: default: 30 description: - The connection timeout when connecting to the MySQL server. type: int login_unix_socket: description: - The path to a Unix domain socket for local connections. type: str single_transaction: default: 'no' description: - Execute the dump in a single transaction type: bool version_added: '2.1' version_added_collection: ansible.builtin