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

# Database connections

> Connect MapX to an external PostgreSQL or MySQL database to query data in chat, import results as layers, or turn PostGIS spatial tables into live map layers.

A database connection links MapX to an external PostgreSQL or MySQL database. Once connected, the AI can inspect the schema and run read-only queries, you can import results as map layers, and PostGIS spatial tables can become live layers on the map — no data export required.

## Add a connection

1. Open **Data sources** in the dashboard.
2. Add a connection with host, port, database name, username, and password.
3. Choose SSL mode (`disable` or `require`) and test the connection.

Passwords are encrypted at rest and never returned by the API. Runtime access happens server-side, so credentials never enter the AI sandbox.

## Query in chat

After connecting, ask the AI to explore the database in plain language:

* "List the tables in my analytics database."
* "Show the columns of the `orders` table."
* "Count orders per region for the last 30 days."

The AI inspects the schema, then runs read-only SQL. Queries are restricted to read-only operations — writes are rejected.

## Import as a map layer

When a table has spatial columns (PostGIS geometry or MySQL spatial types), you can import it directly as a map layer. Non-spatial query results can be visualized as well.

## Use a PostGIS table as a live layer

If your PostgreSQL database uses PostGIS, you can take a spatial table and put it straight on the map as a layer. Choose the table, and MapX renders it like any other layer — style it by attribute, filter it, run analysis on it, and keep it in sync with the database: when the underlying table changes, the layer updates too.

Live PostGIS layers behave like the rest of your layers:

* **Edit in place** — open the attribute table or edit geometry, and changes are written back to the database immediately. See [Editing data and geometry](/en/concepts/layers#editing-data-and-geometry).
* **View in 3D** — database layers support the same columns, raised paths, and extruded areas as uploaded data. See [3D view](/en/concepts/3d-view).

MySQL connections keep their existing behavior: the AI can query them read-only and import query results or spatial tables as map layers, but live database-backed layers are a PostgreSQL (PostGIS) feature.

## Managing connections

Each connection shows its status (`active` or `failed`) and the last check time. You can disable a connection to stop the AI from using it, or re-test it after changing credentials.

<Warning>
  Database connections grant the AI read access to the connected database. Only connect databases you are authorized to read, and keep credentials limited to read-only users where possible.
</Warning>

See [MCP connections](/en/concepts/mcp) for how the AI executes these operations.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.