# Connect an app

Everything needed to connect lives on the database's **Credentials** tab: host, port, database name, user, and password, plus a ready-made connection string with a copy button.

```
postgresql://appuser:PASSWORD@203.0.113.10:5432/mydb?sslmode=require
```

## Set DATABASE_URL

Put the connection string in the app's [environment variables](/platform/environment-variables) - most frameworks and ORMs take a single `DATABASE_URL`:

```
DATABASE_URL=postgresql://appuser:PASSWORD@203.0.113.10:5432/mydb?sslmode=require
```

That covers Prisma, Drizzle, Rails, Laravel, Django (with `dj-database-url`), and most Node, Python, and Go database libraries. Frameworks that want separate values instead - host, user, password, name - take the same fields from the Credentials tab as individual variables.

WordPress apps get a shortcut: pick the database in the app's settings and the `WORDPRESS_DB_*` variables are filled in for you. [Stacks](/create/templates#stacks) arrive wired already.

## TLS

Shared-tier databases **require** TLS on every connection - keep `sslmode=require` (PostgreSQL) or your driver's TLS option (MySQL) in place. Dedicated instances accept TLS too (minimum version 1.2); leave it on unless you have a reason not to.

## One database per environment

Point production at the real database and give [previews](/platform/preview-environments) a database of their own, by overriding `DATABASE_URL` per environment:

- **Production:** the dedicated instance.
- **Previews:** a [Shared-tier database](/platform/databases#the-shared-tier) - ready in seconds, about $3 a month, and disposable.

A preview then can't corrupt production data, and schema experiments stay contained.

## Connect from your laptop

The same connection string works from your machine:

```bash
psql "postgresql://appuser:PASSWORD@203.0.113.10:5432/mydb?sslmode=require"
```

```bash
mysql --host=203.0.113.10 --port=3306 --user=appuser --password --ssl-mode=REQUIRED mydb
```

Run migrations, inspect data, or take an extra dump - it is a normal PostgreSQL or MySQL endpoint.

## Keep the region close

Every query crosses the distance between the app and the database. Create both in the same [region](/create/application-settings#region) - the create form warns when they differ.

> [!TIP]
> Connect lazily. Open the database connection on first use rather than at process start: cold starts get faster, and an app at [zero instances](/create/scaling#min-instances) holds no idle connections.

## Related

- [Databases](/platform/databases): Tiers, the shared pool, storage, and high availability.
- [Backups](/platform/databases/backups): Daily backups, point-in-time recovery, import and export.
- [Environment variables](/platform/environment-variables): Where DATABASE_URL lives, per environment.
