O'Reilly logo

Salt Cookbook by Anirban Saha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required