mysql-server-5.7:
    pkg.installed

python-mysqldb:
    pkg.installed

{% for database, spec in pillar.mysql.items() %}
mysql-db-{{database}}:
    mysql_database.present:
        - name: {{database}}
        - require:
            - pkg: python-mysqldb

mysql-user-{{spec.username}}:
    mysql_user.present:
        - name: {{spec.username}}
        - host: {{spec.host}}
        - password: {{spec.password}}
        - require:
            - mysql_database: mysql-db-{{database}}

mysql-grant-{{spec.username}}:
    mysql_grants.present:
        - grant: 'ALL PRIVILEGES'
        - database: {{ database }}.*
        - user: {{ spec.username }}
        - host: {{ spec.host }}
        - require:
            - mysql_user: mysql-user-{{spec.username}}
{% endfor %}
        

Add simple mysql server state
Add simple mysql server state

This includes installing database based on the data in pillars, which
should generally look like this:

mysql:
  dbname:
    username: foo
    password: bar
    host: localhost

EliRibble/webserver-salt-masterless,EliRibble/webserver-salt-masterless