# MySQL recipe

URL: https://briq.cloud/cookbook/mysql

> A MySQL database with a persistent volume.

Tags: database, sql

Guide:

- [Connect to a database from outside](https://briq.cloud/docs/guides/connect-to-a-database-from-outside.md): A briq's database reachable from psql, a BI tool or an app elsewhere, over TLS, with a normal connection string.

## Run it

MCP:

```ts
briq_run({
  recipe: "mysql",
  params: {
    "version": "8.4",
    "database": "app",
    "size": "small",
    "diskGb": 2
  },
  wait: true
})
```

REST:

```bash
curl -X POST https://api.briq.cloud/v1/briqs \
  -H "Authorization: Bearer $BRIQ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "recipe": "mysql",
    "params": {
      "version": "8.4",
      "database": "app",
      "size": "small",
      "diskGb": 2
    },
    "wait": true
  }'
# → { "briqs": [{ "id": "bq_…", … }], "outputs": { "DATABASE_URL": "…" }, … }

# ... when done, for each briq id
curl -X DELETE https://api.briq.cloud/v1/briqs/<id> \
  -H "Authorization: Bearer $BRIQ_API_KEY"
```

## Parameters

| Name | Type | Options | Default | What it does |
| --- | --- | --- | --- | --- |
| `version` | enum | 8.0, 8.4, 9 | "8.4" | — |
| `database` | string | — | "app" | — |
| `size` | enum | nano, small, medium, large | "small" | — |
| `diskGb` | number | — | 2 | Volume size, in GB |

## Outputs

Returned by `briq_run` once the stack is healthy. Hosts resolve inside your team network; secrets are generated per run.

| Output | Value |
| --- | --- |
| `DATABASE_URL` | `mysql://root:<MYSQL_ROOT_PASSWORD>@mysql.<stack>.internal:3306/app` |
| `MYSQL_HOST` | `mysql.<stack>.internal` |
| `MYSQL_PORT` | `3306` |
| `MYSQL_USER` | `root` |
| `MYSQL_PASSWORD` | `<MYSQL_ROOT_PASSWORD>` |
| `MYSQL_DATABASE` | `app` |

## What it runs

| Briq | Image | Ports | Size | Volume |
| --- | --- | --- | --- | --- |
| mysql | `mysql:8.4` | 3306 | small | 2 GB at /var/lib/mysql |

## When to use it

* Your app targets MySQL or MariaDB and migrations must be checked against the real dialect.
* A test suite expects a `mysql://` `DATABASE_URL`.

## Tips

* **First boot is slow**: MySQL initialises its data directory, so `briq_run` can take 30 to 60
  seconds. Later starts are fast.
* **Root only**, with a generated password (`MYSQL_ROOT_PASSWORD` inside the briq). Create
  least-privilege users with `briq_exec`:
  `sh -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "create user …"'`.
* **Import a dump**: `briq_files_put` it to `/dump.sql`, then `briq_exec` with
  `sh -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" app < /dump.sql'`.
* **Connect from outside**: `briq_expose` port 3306 with `protocol: "mysql"`. The `mysql` CLI
  needs 8.1 or later and `--tls-sni-servername`. See [Connect to a database from outside](https://briq.cloud/docs/guides/connect-to-a-database-from-outside).
* **Bigger dataset?** The volume starts small: pass `diskGb`, e.g. `params: { diskGb: 20 }`. Set it
  when the briq is created, and it counts toward your [plan's disk](https://briq.cloud/docs/cost#plans).
