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

# Database

> Let agents answer questions straight from your MySQL database — strictly read-only

Connect a MySQL database and your agents answer data questions directly from the source: counts, lookups, trends, cross-checks. No dashboards to build, no CSV exports — ask the question, the agent explores the schema and writes the query.

**This integration cannot write.** Every query is checked before it runs: only `SELECT` statements are accepted; inserts, updates, deletes, schema changes, locks, and multi-statement tricks are all rejected. Even so, we recommend connecting with a read-only database user — defense in depth costs nothing.

## What agents can do

| Capability            | Details                                                             |
| --------------------- | ------------------------------------------------------------------- |
| List tables           | Discover what's in the database before querying.                    |
| Describe tables       | Columns, types, nullability, and keys — so queries fit your schema. |
| Run read-only queries | `SELECT`-only, with bounded result sizes.                           |

## Try asking

* *"How many orders did we take yesterday, and what was the total?"*
* *"Which customers signed up this month but never placed an order?"*
* *"What are the 10 best-selling products this quarter?"*
* *"Is there anything unusual in support ticket volume this week?"*
* *"What columns does the subscriptions table have?"*

## Connect a database

<Steps>
  <Step title="Create a read-only user">
    In MySQL, create a dedicated user for Leme and grant it `SELECT` only, on only the schemas agents should see:

    ```sql theme={null}
    CREATE USER 'leme_readonly'@'%' IDENTIFIED BY 'a-strong-password';
    GRANT SELECT ON analytics.* TO 'leme_readonly'@'%';
    ```
  </Step>

  <Step title="Open Integrations">
    In the Leme dashboard, go to **Integrations** and select **Database**.
  </Step>

  <Step title="Enter the connection details">
    Give the connection an **alias** — a short name agents use to refer to this database, like `analytics` — and the connection URL:

    ```text theme={null}
    mysql://leme_readonly:a-strong-password@db.example.com:3306/analytics?ssl=true
    ```

    Leme validates the connection before saving it.
  </Step>

  <Step title="Enable it on your agents">
    Attach the connection to the agents that should use it.
  </Step>
</Steps>

The database must be reachable from Leme's servers. If your database only accepts connections from allowlisted addresses, contact [support](mailto:support@leme.ai) for the addresses to allow.

## Permissions

| Action                                             | Category | Default |
| -------------------------------------------------- | -------- | ------- |
| List tables, describe tables, run `SELECT` queries | Read     | Allow   |

The integration has no write actions, so there is nothing riskier to configure. Remember that "read" here means *anything the connected user can `SELECT`* — scope the MySQL user's grants to the data agents should legitimately see, and keep personal or sensitive tables out of the grant.

## Security notes

* Credentials are stored encrypted and never shown to agents — agents send queries, Leme executes them server-side.
* Use `?ssl=true` in the connection URL so traffic to your database is encrypted in transit.
* Rotating the password? Update it in MySQL, then reconnect in **Integrations → Database** with the new URL.

## Troubleshooting

<AccordionGroup>
  <Accordion title="The connection fails to validate">
    Check the pieces in order: host reachable from the internet, port correct (default 3306), user and password valid, database name present in the URL. The error message says which check failed.
  </Accordion>

  <Accordion title="A query was rejected as not read-only">
    Working as intended — the agent attempted something other than a plain `SELECT`. Rephrase the request as a question about data; if you actually need to change data, that's outside what this integration allows.
  </Accordion>

  <Accordion title="The agent says a table doesn't exist">
    The read-only user probably doesn't have `SELECT` on that schema. Extend the grant in MySQL; no reconnection needed.
  </Accordion>

  <Accordion title="Results seem cut off">
    Query results are bounded to keep answers fast. For large questions, ask for aggregates ("totals per month") instead of raw rows — the agent will push the work into SQL.
  </Accordion>
</AccordionGroup>
