Ansible mysql_db模块
mysql_db模块用于建立、删除、导入和导出数据库
1、建立数据库
state=“present”
---
- hosts: mysql
tasks:
- name: create a database
mysql_db:
login_host: "localhost"
login_user: "root"
login_password: "123.com"
login_port: "3306"
name: "blog"
encoding: "utf8"
state: "present"
2、删除数据库
state=“absent”
---
- hosts: mysql
tasks:
- name: delete a database
mysql_db:
login_host: "localhost"
login_user: "root"
login_password: "123.com"
login_port: "3306"
name: "blog"
encoding: "utf8"
state: "absent"
3、导出数据库
state=“dump”
target: “导出路径.gz”
---
- hosts: mysql
tasks:
- name: dump a database
mysql_db:
login_host: "localhost"
login_user: "root"
login_password: "123.com"
login_port: "3306"
name: "blog"
target: "/usr/local/mysql/data/bak/blog.gz"
state: "dump"
5、导入数据库
state=“import”
target: “导入路径”
---
- hosts: mysql
tasks:
- name: import a database
mysql_db:
login_host: "localhost"
login_user: "root"
login_password: "123.com"
login_port: "3306"
name: "blog"
target: "/usr/local/mysql/data/bak/blog.gz"
state: "import"