N8n MySQL Database
An n8n mysql database integration links workflow automation and AI agents to relational data. Engineers attach a MySQL tool sub-node to an AI Agent node to run queries. This setup lets chat models read tables and write records during a workflow run. Teams use it to automate reports, update customer records, and answer questions from data. Still, giving an automated agent direct database credentials creates real security risks in production. You must understand how the agent node works and how t
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 mysql database integration links workflow automation and AI agents to relational data. Engineers attach a MySQL tool sub-node to an AI Agent node to run queries.
This setup lets chat models read tables and write records during a workflow run. Teams use it to automate reports, update customer records, and answer questions from data. Still, giving an automated agent direct database credentials creates real security risks in production. You must understand how the agent node works and how to control each query.
How an n8n mysql database setup works in practice
In n8n, the AI Agent node builds an agent from a chat model. You must attach at least one tool sub-node to the AI Agent node. The agent then decides which tools to call to finish a given task.
Starting in n8n 1.82.0, the old agent type setting is deprecated for new workflows. Every AI Agent node now runs as a Tools Agent by default. Also, n8n 3.0 removes version 1 of the node and that old setting.
Older versions included a separate SQL Agent option for MySQL, SQLite, and Postgres data. That SQL Agent took plain text questions and turned them into SQL queries. It then ran the queries and showed the results back to the user. For SQL Agent use cases today, the docs recommend a MySQL tool sub-node. You attach that MySQL tool sub-node right to a recent AI Agent node.
Teams can also expand what the agent does by adding other tool sub-nodes. For example, n8n offers a Call n8n Workflow Tool and a Custom Code Tool. You can also attach an HTTP Request Tool or use MCP servers as tools. The agent picks the right tool based on the user prompt and workflow state.
Security tradeoffs of static keys and live agent queries
Connecting a workflow or AI agent to MySQL requires database login credentials. Most teams store a static username and password inside the workflow platform credential store. That account needs database roles that allow reading or writing the target tables.
Database Access Proxy + MySQL Access Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static database roles only check permissions when the connection first opens. Once the session starts, the agent can run any query that role allows. A bad prompt or model error can trigger a slow or destructive query. Standard database roles cannot check the context of an individual workflow run.
Database roles also return full rows of data to the calling tool sub-node. If a table holds emails, phone numbers, card numbers, or national IDs, everything returns. Those raw values then pass into the chat model prompt and workflow logs. Data masking at the query layer solves this by rewriting matched fields in results.
Audit logs are another major challenge when every workflow shares one service account. The MySQL log only shows that the shared n8n user ran a query. Security teams cannot tell which workflow, engineer, or agent task triggered that specific read. Adding identity controls and query checks between the workflow and MySQL closes these gaps.
Best practices for running database workflows in production
Start by giving the n8n database user the smallest possible set of permissions. Create dedicated MySQL accounts for read tasks and separate accounts for write tasks. Do not let a general chat agent share credentials with core billing workflows.
Place a control layer between your automation nodes and the production database server. Use data masking so the system rewrites matched fields in results before returning rows. Require human approval before any workflow or agent runs a schema change or delete. Log every query with the identity of the service or user that started it.
Check MySQL queries and results on the wire
MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.
Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.
Frequently asked questions
How do I build a SQL agent for MySQL in recent n8n versions?
Attach a MySQL tool sub-node to a recent AI Agent node in your workflow. Since n8n 1.82.0, all AI Agent nodes run as a Tools Agent by default.
Why is the old SQL Agent option missing in n8n 3.0?
The agent type setting was deprecated in n8n 1.82.0 and removed in n8n 3.0. You now use a MySQL or Postgres tool sub-node with the standard Agent node.
How can teams protect sensitive data when an n8n agent queries MySQL?
Teams use query-level controls and data masking between n8n and the MySQL server. Masking rewrites matched fields in results for emails, phone numbers, card numbers, and national IDs.
Related guides
In this post