# MySQL

MySQL database server.

Host vars:
```yaml
mysql:
  enable: true                       # required to manage
  bind_address: 127.0.0.1            # optional
  innodb_buffer_pool_size: 3G        # optional
  group_concat_max_len: 320000       # optional
  sql_mode: "STRICT_TRANS_TABLES,..."  # optional
  slow_query_log: true               # optional, default: false
  slow_query_log_file: /var/log/mysql/mysql-slow.log  # optional
  long_query_time: 2                 # optional, seconds
  backup_retention_days: 7           # optional
  backup_schedule: "0 2 * * *"      # optional
  version: 8.0                       # currently not used by the role
```

Defaults:
- `mysql.enable`: not set (role does nothing unless defined)
- `mysql.bind_address`: `127.0.0.1`
- `mysql.innodb_buffer_pool_size`: `3G`
- `mysql.group_concat_max_len`: `320000`
- `mysql.sql_mode`: `STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION`
- `mysql.slow_query_log`: `false`
- `mysql.slow_query_log_file`: `/var/log/mysql/mysql-slow.log`
- `mysql.long_query_time`: `2` (seconds)
- `mysql.backup_retention_days`: `7`
- `mysql.backup_schedule`: `"0 2 * * *"` (daily at 02:00)
- `mysql.root_password`: autogenerated on first install and stored in `/etc/ploy/password.json`
- `mysql.version`: unused

Notes:
- Uses Percona Server (drop-in MySQL replacement).
- App database user passwords are generated and stored in `/etc/ploy/password.json`.
- A `backup` user is created automatically with read-only (`SELECT`) access to all tables.
- MySQL backups run as `ploy` via `/etc/cron.d/ploy-mysql-backup` and write to `/var/www/<appuser>/backups/<datetime>_<databasename>.sql`.
- Enable `slow_query_log` to log queries that take longer than `long_query_time` seconds — useful for identifying performance issues.
