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.
Create and edit
/opt/salt-cookbook/staging/mysql/query.sls
to have the following entries:include: - mysql.database
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
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...