Configure MySQL

Specify the version

The default version is 8.0 (LTS).

To override the version, update the server’s Pillar file:

mysql:
  version: '8.0'

Generate a password hash

manage.py mysql-hash reads a password from standard input, and writes its hash to standard output:

uv run manage.py mysql-hash

Note

password_hash is used instead of password until saltstack/salt#66859 is fixed. Salt can’t verify a password unless the mysql_native_password plugin is used, whereas it can verify a password_hash always.

Add users, groups and databases

To configure the database for an application:

  1. Add a user for the application, in a private Pillar file, replacing PASSWORD with a strong password (uncheck Symbols), HASH with its hash, and USERNAME with a recognizable username:

    mysql:
      users:
        USERNAME:
          password: PASSWORD
          password_hash: "HASH"
          host: "192.0.2.1"
    

    By default, host is set to localhost.

  2. Create the database for the application and grant all privileges to the new user, in a public Pillar file, replacing DATABASE and USERNAME:

    mysql:
      databases:
        DATABASE:
          user: USERNAME
          host: "192.0.2.1"
    
  3. Add the Pillar files to the top file entry for the application.

Configure MySQL

Note

Even if you don’t need to configure MySQL, you must still set the following, in order for its SLS file to be automatically included:

mysql:
  configuration: False
  1. Put your configuration file in the salt/mysql/files/conf directory.

  2. Set mysql.configuration in the server’s Pillar file:

    mysql:
      configuration: myconfig
    
  3. Deploy the server

The configuration file will be in the /etc/mysql/conf.d directory on the server.

Set up backups

  1. Create and configure an S3 backup bucket

  2. Configure the AWS CLI

  3. In the server’s Pillar file, set mysql.backup.location to a bucket and prefix, for example:

    mysql:
      backup:
        location: ocp-coalition-backup/database
    
  4. Deploy the server