N8n Connect to MySQL Database
To make n8n connect to mysql database systems, you add a MySQL node or tool sub-node. You then give it your database host, login details, and query instructions. Teams use this setup for standard automations and AI agent workflows. In recent versions, an AI Agent node links to a chat model and a MySQL tool sub-node. The agent then decides when to call that tool to finish a task. How to make n8n connect to mysql database workflows Standard workflows and AI agents use the same basic link to re
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.
To make n8n connect to mysql database systems, you add a MySQL node or tool sub-node. You then give it your database host, login details, and query instructions.
Teams use this setup for standard automations and AI agent workflows. In recent versions, an AI Agent node links to a chat model and a MySQL tool sub-node. The agent then decides when to call that tool to finish a task.
How to make n8n connect to mysql database workflows
Standard workflows and AI agents use the same basic link to reach your data. You store your host address, database name, user, and password inside the platform credential store. Every node that uses those stored details opens a session with that exact database role.
For AI use cases, the older SQL Agent option is now deprecated. From version 1.82.0 onward, all AI Agent nodes work as a Tools Agent. Node version 1 and its agent type setting are removed in version 3.0. Today, the docs say to attach a MySQL tool sub-node to a recent AI Agent node. You must attach at least one tool sub-node for the agent to run.
When a user sends a prompt, the chat model reads the request and picks a tool. It can convert natural language questions into SQL queries and run them against your tables. The tool then returns the rows to the agent so it can write an answer. You can also link a Call n8n Workflow Tool, a Custom Code Tool, or an HTTP Request Tool. The platform also offers a registry of MCP servers for broader tool use.
Security tradeoffs of static credentials and active sessions
Storing a database user and password inside an automation tool is fast to set up. Database roles let you limit which tables that user can read or change. You can also restrict which network addresses can reach your database port.
Still, static roles do not control what happens inside an active session. Every workflow or AI agent sharing that credential has the exact same table rights. If an AI agent generates a broad query, the database runs it without a second check. The database log only shows the shared automation user, not the person or prompt behind it.
Database Connection Strings Security + MySQL Access Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Sensitive data exposure is another major risk during live query runs. A table with permitido access might hold emails, phone numbers, card numbers, or national IDs. Once the query runs, those fields flow back into the workflow memory or chat model context. Static database permissions cannot rewrite matched fields in results on the fly. They also cannot pause a risky delete or update statement for a human team member to check.
Adding query controls and data masking to workflows
To fix these gaps, teams put a policy layer between the workflow tool and the database. Instead of giving the workflow direct network access and root keys, you route traffic through a proxy. The proxy checks every query before it reaches the MySQL server.
This setup lets you enforce fine-grained rules on every single statement. You can block drop statements or require a quick team approval for data changes. You can also turn on real-time data masking for the query results. Masking rewrites matched fields in results, such as emails, phone numbers, and card numbers. The workflow and chat model still get the rows they need to finish the task. At the same time, every query is tied to an exact identity in your central audit log.
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
Should I use the SQL Agent or a MySQL tool sub-node?
Use a MySQL tool sub-node attached to a recent AI Agent node. From version 1.82.0, the agent type setting is deprecated and all agents work as a Tools Agent.
How do AI agents run queries against MySQL?
You link a chat model and at least one tool sub-node to the AI Agent node. The agent reads the prompt, decides when to call the MySQL tool, and runs the query.
How can I protect sensitive data when workflows query MySQL?
Use a least-privilege database role and route traffic through a proxy that masks data in transit. Data masking rewrites matched fields like emails, phone numbers, card numbers, and national IDs in results.
Related guides
In this post