Author: | Mark Theunissen |
---|
parameter | required | default | choices | comments |
---|---|---|---|---|
collation | no | Collation mode | ||
encoding | no | Encoding mode | ||
login_host | no | localhost | Host running the database | |
login_password | no | The password used to authenticate with | ||
login_port | no | 3306 | Port of the MySQL server | |
login_unix_socket | no | The path to a Unix domain socket for local connections | ||
login_user | no | The username used to authenticate with | ||
name | yes | name of the database to add or remove | ||
state | no | present |
|
The database state |
target | no | Location, on the remote host, of the dump file to read from or write to. Uncompressed SQL files (.sql ) as well as bzip2 (.bz2 ) and gzip (.gz ) compressed files are supported. |
Note
Requires ConfigParser
# 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'
- copy: src=dump.sql.bz2 dest=/tmp
- mysql_db: name=my_db state=import target=/tmp/dump.sql.bz2
Note
Requires the MySQLdb Python package on the remote host. For Ubuntu, this is as easy as apt-get install python-mysqldb. (See apt.)
Note
Both login_password and login_user are required when you are passing credentials. If none are present, the module will attempt to read the credentials from ~/.my.cnf, and finally fall back to using the MySQL default login of root with no password.