MySQL Server installieren

{% set mysql_root_pw = 'xyz' %}

mysql-server:
  pkg.installed:
    - pkgs:
      - mysql-server
      - python-mysqldb

# Setting initial root password with build in state is not working.
# Switch user root to nativ_password
set-mysql-root-pw:
  cmd.run:
    - name: mysql -e "UPDATE mysql.user SET authentication_string=password('{{ mysql_root_pw }}'),plugin='mysql_native_password' WHERE user='root';FLUSH PRIVILEGES;"
    - unless: test -e /root/.my.cnf
    - runas: root
    - cwd: /root/

/etc/mysql/conf.d/innodb.cnf:
  file.managed:
    - contents: |
        [mysqld]
        innodb_file_per_table          = 1
        innodb_doublewrite             = 0
        innodb_flush_log_at_trx_commit = 0
        innodb_support_xa              = No

/root/.my.cnf:
  file.managed:
    - contents: |
        [client]
        user = root
        password = {{ mysql_root_pw }}
    - require:
      - cmd: set-mysql-root-pw

/etc/mysql/mysql.conf.d/mysqld.cnf:
  file.replace:
    - pattern: "bind-address\\s*=\\s*127.0.0.1"
    - repl: "bind-address = 0.0.0.0"

set-mysql-root-host:
  cmd.run:
    - name: mysql -e "UPDATE mysql.user SET host='%' WHERE user='root';FLUSH PRIVILEGES;"
    - unless: mysql -e "SELECT user FROM mysql.user WHERE user='root' AND HOST ='%'"|grep -q root
    - runas: root
    - cwd: /root/

mysql-service:
  service.running:
    - name: mysql
    - enable: True
    - require:
      - pkg: mysql-server
    - watch:
      - file: /etc/mysql/conf.d/innodb.cnf
      - file: /etc/mysql/mysql.conf.d/mysqld.cnf

app-user:
  mysql_user.present:
    - name: app
    - host: localhost
    - password: zabbix
    - connection_user: root
    - connection_pass: {{ mysql_root_pw }}
    - failhard: true

app-db:
  mysql_database.present:
    - name: app
    - host: localhost
    - connection_user: root
    - connection_pass: {{ mysql_root_pw }}
    - character_set: UTF8
    - failhard: true

results matching ""

    No results matching ""