> ## 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.

# 外部データベース

## Helm Chart 値の表示

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

## 外部データベースへの接続

外部データベースとして PostgreSQL、MySQL、または TiDB への接続をサポートしています。

以下は、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
  user: "postgres"
  password: "#REPLACE_ME#"
  timezone: "UTC"
  databases:
    dify: "dify"
    plugin_daemon: "dify_plugin_daemon"
    enterprise: "enterprise"
    audit: "audit"
  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
```

> **注意**
>
> Dify を起動する前に、必要なデータベースを手動で作成する必要があります。

### PostgreSQL

```sql theme={null}
CREATE DATABASE dify;
CREATE DATABASE enterprise;
CREATE DATABASE audit;
-- dify_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 はプラグインデーモンの初回起動時に自動的に作成されます
```

## 設定の説明

| フィールド                     | 説明                                          |
| ------------------------- | ------------------------------------------- |
| `engine`                  | データベースの種類：`postgres`、`mysql`、`tidb`         |
| `databases`               | 各コンポーネントで使用されるデータベース名のマッピング                 |
| `dialectOptions.postgres` | PostgreSQL 専用設定（sslMode、uriScheme、extras 等） |
| `dialectOptions.mysql`    | MySQL/TiDB 専用設定（params、tls 等）               |

### デフォルトポート

| Engine   | デフォルトポート |
| -------- | -------- |
| postgres | 5432     |
| mysql    | 3306     |
| tidb     | 4000     |

## 設定例

### 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"
    extras: ""
  dialectOptions:
    postgres:
      sslMode: "require"
```

### 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"
  dialectOptions:
    mysql:
      params: "charset=utf8mb4&parseTime=true&loc=UTC"
```

### 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"
  dialectOptions:
    mysql:
      params: "charset=utf8mb4&parseTime=true&loc=UTC"
```
