N8n AI Agent MySQL
An n8n ai agent mysql setup connects a chat model to a MySQL tool sub-node. The agent reads user prompts, decides when to call the tool, and runs queries. Teams use this pattern to answer questions from live tables and automate data tasks. In newer n8n releases, the Tools Agent replaces the old SQL Agent mode. You attach at least one tool sub-node so the agent can complete its work. How an n8n ai agent mysql workflow runs in practice An n8n AI Agent node combines a chat model with one or mor
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
An n8n ai agent mysql setup connects a chat model to a MySQL tool sub-node. The agent reads user prompts, decides when to call the tool, and runs queries.
Teams use this pattern to answer questions from live tables and automate data tasks. In newer n8n releases, the Tools Agent replaces the old SQL Agent mode. You attach at least one tool sub-node so the agent can complete its work.
How an n8n ai agent mysql workflow runs in practice
An n8n AI Agent node combines a chat model with one or more tools. During a run, the agent decides which tools to call to finish a task. You must attach at least one tool sub-node to the main agent node.
Starting in n8n 1.82.0, the old agent type setting is deprecated. Every AI Agent node now runs as a Tools Agent by default. Node version 1 with the old setting is removed in n8n 3.0.
Previously, the built-in SQL Agent handled MySQL, SQLite, and Postgres data sources directly. That mode turned plain language into SQL queries, ran them, and returned the results. It also included options such as Included Tables to narrow the schema scope.
For current SQL workflows, n8n docs recommend a MySQL tool sub-node instead. You attach this MySQL tool sub-node to a recent AI Agent node. You can also connect a Call n8n Workflow Tool or a Custom Code Tool. An HTTP Request Tool or an MCP server from the registry also works.
When a user asks a question, the chat model drafts the needed query. The MySQL tool sub-node then sends that statement to your database server. Finally, the database returns rows to the agent, which writes a clear answer.
AI Agent Security + MySQL Access Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Security and operational tradeoffs for AI database access
Connecting an AI agent to a production MySQL database brings new risks. Standard setups store static database keys inside the workflow tool settings. Anyone who can edit the workflow can use those stored database permissions.
Database roles control which tables a MySQL user can read or change. A read-only role stops the agent from dropping tables or deleting rows. Still, static roles cannot inspect the content of individual queries in flight.
Once a session starts, the agent can read all column in allowed tables. If a table holds sensitive data, the query result includes those raw values. Those rows then travel to the external chat model provider inside the prompt.
Masking rules solve this by rewriting matched fields in query results before delivery. For example, masking can replace emails, phone numbers, card numbers, and national IDs. The agent still finishes its task, while sensitive strings get rewritten in results.
Teams also need clear logs of every query an AI agent runs. Shared database users make it hard to trace which workflow ran a command. Adding a control layer between the tool and MySQL gives teams query-level visibility. You can block risky statements, apply data masking, and require human approval for writes.
Add wire guardrails and masking beside MySQL
Database grants and TLS setup decide who can reach MySQL. Even so, an open session can run broad updates or read raw personal data from allowed tables. In practice, hoop.dev sits inline in the wire protocol beside the database as a sidecar for your MySQL. On every production query an agent or engineer sends, hoop.dev decides to pass, mask, block, or escalate it for human review.
With hoop.dev MySQL support, guardrails refuse bad queries before they run or hold risky calls for approval, while data masking rewrites matched sensitive values in result rows in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for GDPR, HIPAA, and PCI DSS programs. Read the docs and source on GitHub.
Frequently asked questions
Should I use the n8n SQL Agent or a MySQL tool sub-node?
Use a MySQL tool sub-node attached to a recent AI Agent node. Since n8n 1.82.0, the agent type setting is deprecated in favor of Tools Agent. Node version 1 with that old setting is removed in n8n 3.0.
Can an n8n AI agent use other tools alongside MySQL?
Yes, the AI Agent node can use one or more attached tool sub-nodes. Along with MySQL, you can attach a Call n8n Workflow Tool or HTTP Request Tool. You can also use a Custom Code Tool or MCP servers from the registry.
How do teams protect sensitive rows when an AI agent queries MySQL?
Start with a read-only MySQL role and limit which tables the tool can query. Then add query-level controls that rewrite matched fields like emails and card numbers in results. This stops raw sensitive values from flowing into external chat model prompts.
Related guides
In this post