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 ...

Get Salt Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.