N8n MySQL Query
An n8n mysql query runs SQL statements against your database from a workflow or agent. You attach a MySQL tool node or standard node using stored database credentials. Teams use these workflows to sync records, build reports, and power AI agents. When an agent runs queries, you must control what it can read and change. A clear setup keeps your data safe while your automations do their work. How an n8n mysql query works in workflows and agents Standard workflows run fixed queries that an engi
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 query runs SQL statements against your database from a workflow or agent. You attach a MySQL tool node or standard node using stored database credentials.
Teams use these workflows to sync records, build reports, and power AI agents. When an agent runs queries, you must control what it can read and change. A clear setup keeps your data safe while your automations do their work.
How an n8n mysql query works in workflows and agents
Standard workflows run fixed queries that an engineer writes ahead of time. You drop a node onto the canvas and link your database credentials. The workflow passes input data into the query and reads the returned rows. This setup works well when the task stays the same every time.
AI workflows work in a much more dynamic way. The n8n AI Agent node pairs a chat model with one or more tools. The agent decides which tools to call to complete a task. You must connect at least one tool sub-node to an AI Agent node.
From n8n 1.82.0, the old agent type setting is deprecated. All AI Agent nodes now work as a Tools Agent by default. Node version 1 with that old setting is removed in n8n 3.0. For SQL tasks, the docs say to attach a MySQL tool sub-node instead.
Older setups used a separate SQL Agent mode for MySQL, SQLite, and Postgres. That agent could read plain English questions and turn them into SQL queries. It would then run the queries and show the results to the user. Today, you can also connect a Call n8n Workflow Tool for tighter control. Teams also use a Custom Code Tool, HTTP Request Tool, or MCP servers.
Security tradeoffs of static database keys and roles
Every database node needs credentials to log in and run statements. Most teams store a static username and password inside the workflow platform. That account has a fixed database role that stays active all the time. If a workflow shares that account, every run gets the same broad rights.
MySQL Access Governance + Database Query Logging: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Database roles control which tables an account can read or update. Still, roles cannot inspect the intent of a single query at runtime. An AI agent might generate a broad query that pulls thousands of rows. It might also try to change records when it should only read them.
Raw query results also bring privacy risks into your automation logs. Tables often hold sensitive fields like emails, phone numbers, card numbers, or national IDs. When a query runs, those values flow right into the workflow execution history. If an AI agent reads the output, those fields go to the model provider.
Static keys also make audit trails much harder to read. The database log only shows the single shared service account name. You cannot tell which user or agent trigger ran a specific statement. Adding a control layer between the tool and the database fixes these gaps. It lets you check queries in flight and rewrite sensitive fields in results.
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 you connect MySQL to an n8n AI agent?
Add an AI Agent node to your canvas and attach a chat model. Then connect a MySQL tool sub-node so the agent can call it when needed.
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 version 1.82.0. Attach a MySQL tool sub-node instead of using the deprecated SQL Agent setting.
How can teams protect sensitive data during an n8n mysql query?
Use a least-privilege database role and route traffic through a policy proxy. Data masking rewrites matched fields like emails, phone numbers, and card numbers in results.
Related guides
In this post