CTRLctrl docs

Databases

CTRL can give your app a managed MySQL database. It runs MySQL 8.4 on the same node as your app, and its connection details go into your app's env vars.

Create a database#

In the dashboard, open your app, go to the storage tab and find the ctrl db panel. Click + add database.

With the API, there is no request body:

curl -X POST https://api.getctrl.dev/v1/apps/my-api/database \
  -H "Authorization: Bearer $CTRL_API_KEY"

The answer is 201:

{
  "database_id": "my-api-db",
  "db_name": "my_api_db",
  "db_user": "u_abc12345",
  "host": "10.0.0.2",
  "port": 3306,
  "connection_string": "mysql://u_abc12345:<password>@10.0.0.2:3306/my_api_db",
  "status": "active"
}

This is the only time the API returns the password. Save it, or read it later from your app's env vars.

You can also ask for a database when you create an app, with "add_database": true in the body of POST /v1/apps. If the database can't be made, the app still deploys, and the answer's database_error says why.

Errors#

Status Error
404 not found
409 database already exists for this app
409 database name <name> is already in use on this node
503 no database node available for this app on <node> in region <region>
503 MySQL is still booting on this node; try again in a minute
502 mysql init failed: ... or db create failed: ...

The first database on a node starts MySQL there, which can take a few minutes. Until it's up you get the 503 above, with a Retry-After: 30 header. Try again then.

Env vars#

Creating a database adds these env vars to your app:

Name Value
DATABASE_URL The full connection string
DB_HOST The database's address
DB_PORT 3306
DB_NAME The database name
DB_USER The database user
DB_PASSWORD The user's password

Any vars you had with these names are replaced.

Your app doesn't pick them up until it next deploys. Redeploy it after you add a database. See lifecycle.

The connection string has this form:

mysql://<DB_USER>:<DB_PASSWORD>@<DB_HOST>:3306/<DB_NAME>

The host is a private address on your app's node. Only your app can reach it, so connect from inside the app, not from your laptop.

When you copy env vars from another app, these six are skipped. Copied as they are, they would point one app at the other's database.

See your database#

The ctrl db panel shows the connection string, the database, user, host and port. The password is hidden: click the eye to show it, or copy the whole string.

With the API:

curl https://api.getctrl.dev/v1/apps/my-api/database \
  -H "Authorization: Bearer $CTRL_API_KEY"

This returns the same fields as when you created it, plus created_at. The password in connection_string shows as ****. If the app has no database, you get 404 with no database for this app.

Backups#

CTRL backs up every database once a day, at 03:00 UTC. A backup is a compressed mysqldump of your database, stored in Cloudflare R2. You can't start one yourself yet.

A backup is running, then completed or failed. The ctrl db panel shows the five most recent. The API lists them all, newest first:

curl https://api.getctrl.dev/v1/apps/my-api/database/backups \
  -H "Authorization: Bearer $CTRL_API_KEY"
[
  {
    "id": "backup-uuid",
    "r2_key": "backups/my-api-db/2026-11-25.sql.gz",
    "size_bytes": 1048576,
    "status": "completed",
    "created_at": "2026-11-25 03:00:00",
    "finished_at": "2026-11-25 03:00:04"
  }
]

Backups don't count against your blocks.

Restore a backup#

A restore overwrites all the data in your database with the backup's.

In the dashboard, click restore next to a completed backup and confirm. With the API:

curl -X POST https://api.getctrl.dev/v1/apps/my-api/database/restore \
  -H "Authorization: Bearer $CTRL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "backup_id": "backup-uuid" }'

The answer is { "ok": true, "backup_id": "backup-uuid" } once the restore is done.

Before it imports anything, CTRL checks the backup and copies your database as it is now. If the import fails, that copy goes back, and the error says the database is back as it was.

Status Error
400 body must be a JSON object with string backup_id
400 backup is not in completed state
404 backup not found
502 restore failed: ...

Delete a database#

Deleting drops the database, its user and all its data. In the dashboard, click delete database and confirm. With the API:

curl -X DELETE https://api.getctrl.dev/v1/apps/my-api/database \
  -H "Authorization: Bearer $CTRL_API_KEY"

The six env vars above are removed from your app. Your app keeps the old values until it next deploys, so redeploy it.

Once a database is deleted, you can no longer list or restore its backups.

Limits#

  • One database per app.
  • MySQL only.
  • The database runs on your app's node. That node needs a database node set up in your app's region; if it has none, you get the 503 above.
  • Databases are free: they don't count against your blocks.