N8n MySQL MCP

Published
Length
3 min read

Luis Felipe Dias

All posts

An n8n mysql mcp setup links an n8n AI Agent node to a MySQL database. The agent picks the right tool to read or write database rows for your task. Teams use this setup to let chat models answer plain questions with live database facts. You can link a built-in MySQL tool sub-node or pick a server from the n8n MCP registry. How n8n mysql mcp works in practice The n8n AI Agent node builds an agent from one chat model and attached tools. You must attach at least one tool sub-node to the AI Agen

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 mcp setup links an n8n AI Agent node to a MySQL database. The agent picks the right tool to read or write database rows for your task.

Teams use this setup to let chat models answer plain questions with live database facts. You can link a built-in MySQL tool sub-node or pick a server from the n8n MCP registry.

How n8n mysql mcp works in practice

The n8n AI Agent node builds an agent from one chat model and attached tools. You must attach at least one tool sub-node to the AI 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 and its agent type setting are removed in n8n 3.0.

The older SQL Agent used to turn plain questions into SQL queries and run them. Now, official n8n docs say to use a MySQL tool sub-node with a recent Agent node. Besides built-in nodes, n8n also offers a registry of MCP servers for agent tasks. You can also attach a Call n8n Workflow Tool, Custom Code Tool, or HTTP Request Tool.

When a user asks a question, the chat model reads the prompt first. The agent decides which tools to call to finish the task. It sends a query through the MySQL tool sub-node or the chosen MCP server. The database runs the query and sends the rows back to the agent. Last, the chat model turns those rows into a clear answer for the user.

Security and operational tradeoffs for database agents

Linking an AI agent to a live MySQL database creates real operational risks. An n8n tool sub-node or MCP server needs database keys to log in. Most teams store a static username and password inside the workflow tool settings.

MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Database roles can limit which tables that static user account can read or change. You can also set included tables on older SQL setups to narrow the scope. Still, a static database role applies the exact same rules to every single agent run.

Once the session starts, the database cannot tell which human triggered the n8n workflow. Every query in the database log shows the same shared n8n service account. If an agent writes a bad delete query, a broad role will run it right away. Also, a read role still returns full rows to the chat model. Sensitive fields like emails, phone numbers, card numbers, and national IDs flow straight into the prompt.

What to check before production deployment

Before you put an agent in production, review how queries reach your MySQL host. Check if you can inspect individual SQL statements before the database runs them. Make sure your team can require human approval when an agent tries to change data.

You should also plan how to handle sensitive user data in query results. Masking rules that rewrite emails or card numbers in results keep raw data out of prompts. Tying each query to an individual identity also makes your audit logs useful during reviews.

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 n8n SQL Agent or the Tools Agent for MySQL?

Use the standard AI Agent node, which works as a Tools Agent since n8n 1.82.0. The old agent type setting is deprecated and removed in n8n 3.0. Attach a MySQL tool sub-node or an MCP server to a recent Agent node instead.

How does an n8n agent decide when to query MySQL?

You attach a chat model and at least one tool sub-node to the AI Agent node. When a prompt arrives, the agent decides which tools to call to complete the task. It only calls the MySQL tool when it needs database facts.

Why are static MySQL credentials risky for AI agents?

Static keys give every workflow run the same database permissions and hide who asked the question. If a prompt tricks the model, the agent can read or change any allowed table. Also, raw results with emails or card numbers pass straight to the chat model.

The query runs. The emails stay hidden.