[mysql_db模块][1]用于建立、删除、导入和导出数据库
#### 建立数据库
`state="present"`
```
---
- name: mysql
hosts: s.hi.com
tasks:
- name: create a database
mysql_db:
login_host: "127.0.0.1"
login_user: "root"
login_password: "mysql@123"
login_port: "3306"
name: "mezz"
encoding: "utf8"
state: "present"
```
#### 删除数据库
`state="absent"`
```
---
- name: mysql
hosts: s.hi.com
tasks:
- name: delete a database
mysql_db:
login_host: "127.0.0.1"
login_user: "root"
login_password: "mysql@123"
login_port: "3306"
name: "mezz"
state: "absent"
```
#### 导出数据库
`state="dump"`
```
---
- name: mysql
hosts: s.hi.com
tasks:
- name: dump a database
mysql_db:
login_host: "127.0.0.1"
login_user: "root"
login_password: "mysql@123"
login_port: "3306"
name: "mezz"
target: "/tmp/mezz.gz"
state: "dump"
```
#### 导入数据库
`state="import"`
```
---
- name: mysql
hosts: s.hi.com
tasks:
- name: import a database
mysql_db:
login_host: "127.0.0.1"
login_user: "root"
login_password: "mysql@123"
login_port: "3306"
name: "mezz"
target: "/tmp/mezz.gz"
state: "import"
```
[1]:http://docs.ansible.com/ansible/latest/mysql_db_module.html
- 目录
- ansible基础
- ansible简介
- ansible安装和测试
- ansible配置文件
- 常用命令
- yaml在ansible中的用法
- inventory
- 变量与facts
- when语句
- handler模块
- 大杂烩
- ansible模块
- assert 模块
- copy模块
- cron模块
- debug模块
- django_manage模块
- file模块
- filesystem模块
- git模块
- hostname模块
- lineinfile模块
- mount模块
- mysql_user模块
- mysql_db模块
- pip模块
- selinux
- setup模块
- shell 和 command 模块
- stat模块
- supervisorctl
- systemd
- timezone
- unarchive模块
- user模块
- wait_for
- yum和service模块
- 其他模块或者方法
- setup模块
- url模块
- slack 模块
- pause 模块
- 其他
- 报错处理
- playbooks
- 复杂的playbook
- 循环
- roles
- YAML
- jinja2