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

Using MySQL databases

In this recipe, you will learn how to create and remove databases in MySQL. You will also learn how to interrelate these definitions with other Salt definitions, and make all the database components work together.

How to do it...

We will use the same minion as the previous recipe.

  1. Create and edit /opt/salt-cookbook/staging/mysql/database.sls to have the following entries:
    include:
      - mysql
    
    MySQL-python:
      pkg.installed
    
    stg_databases:
      mysql_database.present:
        - name: stagingdb
        - require:
          - pkg: MySQL-python
          - service: mysql_service
    
    databases_to_remove:
      mysql_database.absent:
        - name: test
        - require:
          - pkg: MySQL-python
          - service: mysql_service
  2. Apply the state to the minion, using the following command:
    [root@salt-master ~]# salt 'salt-minion-mysql' ...

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