# Connect with Database

***

## Overview

The **Connect with Database** feature lets your bot connect directly to external databases, so it can use structured data in real time. This enriches the bot’s knowledge base and enables dynamic, accurate answers.

Supported databases: **PostgreSQL** and **MySQL**.

![Figure 1. Connect with database panel](/files/ITQIBZ3QYkk5kbeHmw0J)

## Steps to Use

1\. Access the Database Tab

* Go to **Training Data** → **Connect with Database**.

#### 2. Add a New Database Connection

1. Click **Add Database**.
2. Fill in the form:
   * **DB Name**: Friendly name for the connection.
   * **Type**: PostgreSQL or MySQL.
   * **Host**: Server hostname or IP.
   * **Port**: Database port.
   * **Username / Password**: Login credentials.
   * **Require SSL**: Toggle if SSL is needed.
3. Click **Create** to connect.

#### 3. Manage Connections

* After setup, the database appears in the list with name, partial connection string, and last update.
* Use **✏️ Edit** to update details, or **🗑️ Delete** to remove.

#### 4. View & Edit Tables and Columns

* Click the database name to open tables and columns.
* Select a table → view its columns.
* Click **ℹ️ Info** beside a table/column to add descriptions.
  * Add descriptions to explain the purpose/meaning.
  * Leave blank if you don’t want the bot to use that data.

#### 5. Sync with the Bot

* After updating descriptions, click **Sync to bot’s knowledge**.
* This pushes schema and metadata into the bot’s knowledge base.
* Sync again after any schema or description change.

<figure><img src="/files/pWWL4piCx68xN3kPqcMJ" alt=""><figcaption><p>Figure 2. Database management panel</p></figcaption></figure>

## Notes

* Use **snake\_case** (lowercase letters with underscores) for column names (avoid uppercase or special characters).
* Write **clear, meaningful descriptions** for better accuracy.
* Only structured data with descriptions will be used — blank ones are ignored.
* Keep credentials secure and update if server settings change.
* Always re-sync after schema changes to refresh knowledge.

***

## Quick Tips

* Start with the most relevant tables (e.g., orders, customers).
* Add short but descriptive notes for columns (e.g., `order_date` = “Date when order was created”).
* Test queries with the bot after syncing to confirm data mapping.

## Troubleshooting

* **Connection fails** → Check host, port, and credentials.
* **SSL error** → Ensure SSL is enabled in both DB and CX Genie.
* **Bot not retrieving data** → Confirm table/column descriptions were added and synced.
* **Schema updated but not reflected** → Run **Sync to bot’s knowledge** again.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documents.cxgenie.ai/bots/training-your-bot/connect-with-database.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
