ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[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