Book Image

Salt Cookbook

By : Anirban Saha
Book Image

Salt Cookbook

By: Anirban Saha

Overview of this book

Table of Contents (18 chapters)
Salt Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Running MySQL queries


Apart from managing configuration tasks in MySQL, Salt enables us to run SQL queries on databases using appropriate modules, in turn, providing us with a lot of flexibility for database management. In this recipe, you will learn how to run queries on MySQL databases using Salt.

How to do it...

We will use the same minion as the previous recipe.

  1. Create and edit /opt/salt-cookbook/staging/mysql/query.sls to have the following entries:

    include:
      - mysql.database
  2. Create the first table:

      mysql_query.run:
        - database: stagingdb
        - query: "create table first_table(id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100) NOT NULL, PRIMARY KEY ( id ));"
        - output:   "/tmp/create_first_table.txt"
        - require:
          - mysql_database: stg_databases
  3. Create the second table:

      mysql_query.run:
        - database: stagingdb
        - query: "create table second_table(id INT, address VARCHAR(100));"
        - output:   "/tmp/create_second_table.txt"
        - require:
          - mysql_database: stg_databases...