How to Connect MySQL to an AI Agent: Step-by-Step Guide

· DoubleX

Quick answer

To connect MySQL to an AI agent, prepare a read-only database user, add the MySQL connector in DoubleX Agentes with your host and credentials, choose which agents may use it, and test with a simple question. The connection is read-only by default, so the agent can query tables but not change them.

Most business data lives in a database that only a few people know how to query. Connecting MySQL or MariaDB to an AI agent lets your team ask questions in plain language while the database stays protected. This guide covers what to prepare, how to connect, how to limit access, and how to run your first test.

What does the MySQL connector let an agent do (and why is it read-only)?#

The MySQL connector lets an agent query the tables of a MySQL or MariaDB database directly, in read-only mode. Read-only is the default because the most common need is answering questions, and a connection that cannot write cannot accidentally change or delete records.

A connector is a system linked to the platform, whose tools agents can use. With MySQL connected, an agent can look at your tables, run queries, and explain the results.

In practice, this covers requests such as:

  • Counting orders by status in a orders table.
  • Listing customers who have not purchased recently.
  • Summing revenue by month from an invoices table.

What should you prepare before connecting a MySQL or MariaDB database?#

Before connecting, gather the connection details and create a database user that can only read. Doing this on the database side gives you a second layer of protection on top of the read-only mode.

Use this checklist:

ItemWhat to do
Host and portConfirm the address where the database accepts connections and that it is reachable from outside your private network.
Database nameDecide which database the agent should see.
Dedicated userCreate a new user just for the agent, not your admin account.
PermissionsGrant only SELECT, and only on the tables the agent needs.
DocumentationWrite down what the main tables and columns mean.

How do you add the MySQL connector in DoubleX Agentes?#

You add it from the Connectors screen by choosing MySQL and entering your database details. The same connector works for MariaDB. Credentials are stored encrypted with AES-256-GCM.

If you are new to the platform, create a free account first (no card needed) and take the diagnostic, a 5 to 10 minute conversation about your routine, so you know where to start. The Quickstart walks through the first steps.

Then follow these steps:

  1. Open Connectors and select MySQL.
  2. Enter the host, port, database name, and the read-only user and password you prepared.
  3. Save the connection and confirm it works.
  4. Decide who can use it: only you, your team, or the whole company.
  5. Go to Agents and open the agent that should use the database, or create one by describing what it should do.

For details on managing connectors programmatically, see the Connectors API reference.

How do you choose which agents use the connection and what actions they can run?#

For each agent, you choose which systems it can use and, within each system, which actions it is allowed to run. An agent that is not given the MySQL connector cannot touch the database at all.

A sensible setup looks like this:

AgentUses MySQL?Why
Sales reporting agentYesNeeds order and revenue tables.
Customer support agentNoWorks from email and help articles.
Finance agentYes, on selected tablesReconciles invoices with data.

Because the connection is read-only, there are no write actions to switch on. You can also keep the connector scoped to a team rather than the whole company, using the roles of owner, admin, and member.

How do you test with your first question to the database?#

Start with a simple, easy-to-verify question and compare the answer with a result you already know. This confirms the connection, the permissions, and the agent's understanding of your tables.

Copy any of these requests:

  • "List the tables you can see in the connected MySQL database and describe what each one seems to store."
  • "How many rows are in the orders table?"
  • "Show the 10 most recent orders with customer name, status, and total."
  • "Sum the total of orders by month for this year and give me the result as a table."

If the numbers match what you expect, move on to more complex questions. If they do not, check the table descriptions in the Brain and the permissions of the database user. For more ideas, see MySQL with an AI Agent: Example Requests and Routines.

How does the task history show each query the agent ran?#

Every request to an agent becomes a task in the Tasks screen, with the full history: your request, each tool the agent used, and the result. You can see who asked, what was done, and when.

This lets you audit the queries behind any answer instead of trusting a number blindly. If a result looks wrong, open the task, check the query, and adjust your instructions or table descriptions. For a broader look at asking questions without writing SQL, read How to Query Your Database with AI Without Writing SQL.

Frequently asked questions#

Does it work with MariaDB?#

Yes. The MySQL connector covers both MySQL and MariaDB databases, in read-only mode.

Can the agent change or delete data in my database?#

No. The connection is read-only by default, so the agent can query tables but not write to them. For extra safety, also give the database user SELECT permission only.

Is my data used to train AI models?#

No. Your company content is not used to train models, and requests only go to AI providers that do not use what they receive for training. Each company also has its own separate database on the platform.

Do I need to know SQL?#

No. You describe what you want in your own words and the agent builds the query. You can still review each query in the task history.

Can I run a query on a schedule?#

Yes. You can set up a routine so an agent runs at a set time, such as every Monday at 8am. See Triggers for how routines are defined.