> ## Documentation Index
> Fetch the complete documentation index at: https://enterprise-docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# External Database

## View Helm Chart default values

```bash theme={null}
helm show values dify/dify
```

***

## Connect to an external database

You can use **PostgreSQL, MySQL, or TiDB** as an external database.

Below is a generic configuration example for the external database in the updated Helm chart:

```yaml theme={null}
###################################
# External database (Postgres/MySQL/TiDB)
###################################
externalDatabase:
  enabled: false
  # postgres | mysql | tidb
  engine: "postgres"
  host: "localhost"

  # Default ports: postgres=5432, mysql=3306, tidb=4000
  # Note: when switching engine, remember to update port accordingly
  port: 5432

  # Global database credentials (used by default)
  user: "postgres"
  password: "#REPLACE_ME#"

  timezone: "UTC"

  databases:
    dify: "dify"
    plugin_daemon: "dify_plugin_daemon"
    enterprise: "enterprise"
    audit: "audit"

  ###################################
  # Per-database credentials (optional)
  ###################################
  # Configure username and password independently for each database
  # These take precedence over the global user/password
  # If empty, fallback to the global credentials
  databaseCredentials:
    dify:
      user: ""
      password: ""
    enterprise:
      user: ""
      password: ""
    audit:
      user: ""
      password: ""
    plugin_daemon:
      user: ""
      password: ""


  dialectOptions:
    postgres:
      sslMode: "require"
      uriScheme: "postgresql"
      # extras: "options=-c search_path=your-schema -c your-other-option=xxx"
      extras: ""

    mysql:
      # MySQL/TiDB params, e.g. charset=utf8mb4&parseTime=true&loc=UTC
      params: "charset=utf8mb4&parseTime=true&loc=UTC"
      tls: false
```

***

## ⚠️ Important

Before starting Dify, create the required databases manually:

***

## Database initialization

### PostgreSQL

```sql theme={null}
CREATE DATABASE dify;
CREATE DATABASE enterprise;
CREATE DATABASE audit;
-- dify_plugin_daemon is created automatically on first startup of the plugin daemon
```

***

### MySQL / TiDB

```sql theme={null}
CREATE DATABASE IF NOT EXISTS dify;
CREATE DATABASE IF NOT EXISTS enterprise;
CREATE DATABASE IF NOT EXISTS audit;
-- dify_plugin_daemon is created automatically on first startup of the plugin daemon
```

***

## Configuration reference

| Field                   | Description                                                              |
| ----------------------- | ------------------------------------------------------------------------ |
| engine                  | Database engine: `postgres` / `mysql` / `tidb`                           |
| databases               | Mapping of database names used by each component                         |
| databaseCredentials     | (New) Per-database credentials; takes precedence over global credentials |
| dialectOptions.postgres | PostgreSQL-specific options (e.g. `sslMode`, `uriScheme`, `extras`)      |
| dialectOptions.mysql    | MySQL/TiDB-specific options (e.g. `params`, `tls`)                       |

***

## Per-database credentials behavior

Precedence:

```
databaseCredentials[db] > global user/password
```

* If a database has its own credentials configured → use those credentials
* If empty → fall back to global `user/password`

***

## Default ports

| Engine   | Default port |
| -------- | ------------ |
| postgres | 5432         |
| mysql    | 3306         |
| tidb     | 4000         |

***

## Configuration examples

***

### External PostgreSQL

```yaml theme={null}
externalDatabase:
  enabled: true
  engine: "postgres"
  host: "postgres.example.com"
  port: 5432

  user: "postgres"
  password: "******"

  databases:
    dify: "dify"
    plugin_daemon: "dify_plugin_daemon"
    enterprise: "enterprise"
    audit: "audit"

  databaseCredentials:
    dify:
      user: ""
      password: ""
    enterprise:
      user: ""
      password: ""
    audit:
      user: ""
      password: ""
    plugin_daemon:
      user: ""
      password: ""

  dialectOptions:
    postgres:
      sslMode: "require"
```

***

### External MySQL

```yaml theme={null}
externalDatabase:
  enabled: true
  engine: "mysql"
  host: "mysql.example.com"
  port: 3306

  user: "root"
  password: "******"

  databases:
    dify: "dify"
    plugin_daemon: "dify_plugin_daemon"
    enterprise: "enterprise"
    audit: "audit"

  databaseCredentials:
    dify:
      user: ""
      password: ""
    enterprise:
      user: ""
      password: ""
    audit:
      user: ""
      password: ""
    plugin_daemon:
      user: ""
      password: ""

  dialectOptions:
    mysql:
      params: "charset=utf8mb4&parseTime=true&loc=UTC"
```

***

### External TiDB

```yaml theme={null}
externalDatabase:
  enabled: true
  engine: "tidb"
  host: "tidb.example.com"
  port: 4000

  user: "root"
  password: "******"

  databases:
    dify: "dify"
    plugin_daemon: "dify_plugin_daemon"
    enterprise: "enterprise"
    audit: "audit"

  databaseCredentials:
    dify:
      user: ""
      password: ""
    enterprise:
      user: ""
      password: ""
    audit:
      user: ""
      password: ""
    plugin_daemon:
      user: ""
      password: ""

  dialectOptions:
    mysql:
      params: "charset=utf8mb4&parseTime=true&loc=UTC"
```
