# How to Connect Logto to a MySQL Database (and Why It's Not Supported)

>  Logto does not support MySQL it exclusively requires PostgreSQL from the DB_URL environment variable Learn why and how to configure your database connection

- Repository: [Logto/logto](https://github.com/logto-io/logto)
- Tags: how-to-guide
- Published: 2026-07-03

---

**Logto does not support MySQL and exclusively requires PostgreSQL as its database backend, reading the connection string from the `DB_URL` environment variable.**

Logto is an open-source identity and access management (IAM) platform built with TypeScript and TypeORM. While the question asks specifically about MySQL connectivity, the source code reveals that Logto’s architecture is strictly coupled to PostgreSQL-specific drivers and migration scripts.

## Why Logto Requires PostgreSQL

The Logto monorepo contains no MySQL client libraries, dialect configurations, or compatibility layers. Instead, the codebase depends on the `pg` driver and PostgreSQL-specific TypeORM implementations.

### Database Configuration in GlobalValues.ts

In [`packages/shared/src/node/env/GlobalValues.ts`](https://github.com/logto-io/logto/blob/main/packages/shared/src/node/env/GlobalValues.ts), the application defines the `databaseUrl` property by strictly reading the `DB_URL` environment variable. The implementation assumes a PostgreSQL protocol, and the validation logic will throw errors if the connection string is missing or malformed according to PostgreSQL URI standards.

### TypeORM and Driver Dependencies

Logto uses TypeORM with PostgreSQL-specific settings. The [`package.json`](https://github.com/logto-io/logto/blob/main/package.json) files across the repository list `pg` as a dependency, and there are no `mysql`, `mysql2`, or `mariadb` drivers present. The ORM configuration explicitly targets PostgreSQL system tables and wire protocols, making MySQL connections impossible without modifying the core dependency tree.

## What Happens When You Attempt MySQL Connection

If you configure `DB_URL` with a MySQL connection string (for example, `mysql://user:pass@localhost:3306/logto`), Logto will fail to start. The TypeORM initialization in `packages/core` expects PostgreSQL-specific system catalogs and the `pg` wire protocol, resulting in immediate connection errors when encountering a MySQL server.

## Alternative Approaches

Since native MySQL support does not exist, you have three viable paths:

**Deploy PostgreSQL (Recommended)** – Run a standard PostgreSQL instance locally via Docker, use a managed service like AWS RDS, or deploy the official container defined in the repository’s [`docker-compose.yml`](https://github.com/logto-io/logto/blob/main/docker-compose.yml). This is the only supported configuration.

**Database Proxy Workarounds** – You could theoretically place a translation layer like `pgbouncer` or an ODBC bridge between Logto and MySQL, but this is not tested, officially supported, or documented by the Logto maintainers.

**Fork and Extend** – If your organization mandates MySQL, you must fork the Logto repository, replace the TypeORM PostgreSQL driver with MySQL equivalents, rewrite all migration scripts in `packages/schemas`, and adapt SQL queries using PostgreSQL-specific syntax. This represents a substantial engineering effort outside the scope of standard Logto support.

## Configuring Logto with PostgreSQL

To properly run Logto, configure the `DB_URL` environment variable with a valid PostgreSQL connection string.

**Step 1:** Start a PostgreSQL container:

```bash
docker run -d \
  --name logto-postgres \
  -e POSTGRES_USER=postgres \
  -e POSTGRES_PASSWORD=p0stgr3s \
  -e POSTGRES_DB=logto \
  -p 5432:5432 \
  postgres:17-alpine

```

**Step 2:** Export the connection string:

```bash
export DB_URL="postgres://postgres:p0stgr3s@localhost:5432/logto"

```

**Step 3:** Seed the database (first run only):

```bash
pnpm cli db seed

```

**Step 4:** Start the application:

```bash
pnpm start:dev

```

Logto will read `DB_URL`, connect to PostgreSQL, and execute its built-in migrations automatically.

## Key Source Files Confirming PostgreSQL Requirement

- **[`packages/shared/src/node/env/GlobalValues.ts`](https://github.com/logto-io/logto/blob/main/packages/shared/src/node/env/GlobalValues.ts)** – Defines `databaseUrl` parsing from `DB_URL` and enforces PostgreSQL protocol assumptions
- **[`packages/cli/src/commands/install/utils.ts`](https://github.com/logto-io/logto/blob/main/packages/cli/src/commands/install/utils.ts)** – Writes the database configuration to `.env` during the CLI installation process
- **[`docker-compose.yml`](https://github.com/logto-io/logto/blob/main/docker-compose.yml)** – Demonstrates the official PostgreSQL container setup and `DB_URL` configuration
- **[`packages/core/jest.setup.js`](https://github.com/logto-io/logto/blob/main/packages/core/jest.setup.js)** – Test environment explicitly sets `process.env.DB_URL = 'postgres://mock.db.url'`, confirming PostgreSQL is the only tested dialect

## Summary

- Logto **only supports PostgreSQL** and cannot connect to MySQL databases
- The `DB_URL` environment variable must contain a valid PostgreSQL connection string for the application to initialize
- Attempting to use MySQL will cause TypeORM connection failures and prevent the application from starting
- Using Logto with MySQL would require forking the repository and rewriting the entire data access layer

## Frequently Asked Questions

### Can I use MySQL with Logto if I modify the connection string?

No. Logto's TypeORM configuration and migration scripts in `packages/schemas` are PostgreSQL-specific. Changing `DB_URL` to a MySQL DSN will result in startup errors because the application lacks MySQL drivers and expects PostgreSQL system tables and features like JSONB columns.

### Why doesn't Logto support multiple database types like MySQL?

The Logto team focuses on PostgreSQL to leverage advanced features such as JSONB indexing, row-level security, and specific UUID generation functions. Supporting multiple database engines would require maintaining separate migration paths, query syntax variations, and testing matrices, which the maintainers have chosen not to prioritize for architectural consistency.

### Is there a way to migrate existing Logto data from PostgreSQL to MySQL?

There is no official migration path from PostgreSQL to MySQL. If you absolutely require data in MySQL, you would need to export the PostgreSQL data, manually transform schema types (such as JSONB to TEXT), adjust UUID formats, and import into a custom MySQL-compatible fork of Logto that you maintain independently.

### What PostgreSQL versions are compatible with Logto?

Logto generally supports PostgreSQL 14 and later versions. The [`docker-compose.yml`](https://github.com/logto-io/logto/blob/main/docker-compose.yml) file in the repository typically specifies recent versions like `postgres:17-alpine`, which indicates the maintainers test against the latest stable PostgreSQL releases.