How to Configure n8n MySQL Least Privilege
To set up n8n mysql least privilege, create a dedicated database account with narrow table grants. Then store those scoped credentials in your n8n workflow settings. Many teams start by reusing a broad admin login to build workflows fast. That shortcut lets any shared workflow or AI agent read or change every table. How n8n mysql least privilege works in native setups In n8n, workflows and AI agents connect to databases through stored credential entries. When you build an AI Agent node, you l
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 set up n8n mysql least privilege, create a dedicated database account with narrow table grants. Then store those scoped credentials in your n8n workflow settings. Many teams start by reusing a broad admin login to build workflows fast. That shortcut lets any shared workflow or AI agent read or change every table.
How n8n mysql least privilege works in native setups
In n8n, workflows and AI agents connect to databases through stored credential entries. When you build an AI Agent node, you link a chat model and tool sub-nodes. The agent then decides which tools to call to finish its task. For database tasks, n8n recommends attaching a MySQL tool sub-node to a recent AI Agent node. Older n8n versions used a separate SQL Agent type for natural language database queries. From n8n 1.82.0, the agent type setting is deprecated, and version 3.0 removes node version 1. Every current AI Agent node now runs as a Tools Agent.
On the database side, MySQL checks permissions when the n8n account logs in and runs queries. A least privilege setup avoids giving the workflow account global database rights. Instead, an admin creates a specific MySQL user just for n8n. The admin grants that user read or write rights only on the required tables. If a workflow only reads order totals, the MySQL user gets read access on that table. If an agent tries to drop a table, MySQL blocks the query right away. Teams often create separate MySQL users for different n8n workflows to keep permissions tight.
Why static database grants leave runtime gaps
Native MySQL roles do a great job of blocking access to off-limits tables. They decide which database user can log in and which tables that user can touch. Still, static grants cannot inspect what individual SQL statements do in flight. Once a query targets an allowed table, MySQL runs it and returns every requested row.
This creates a gap when n8n AI agents generate queries on the fly. An agent with read access to a customer table can fetch emails, phone numbers, or card numbers. Native table grants cannot rewrite matched fields in results before they reach the chat model. Also, shared n8n credentials make database audit logs hard to trace. MySQL only sees the shared n8n user login, not which workflow run triggered the query. If an agent needs temporary write access for one step, the MySQL user keeps that right forever.
Least Privilege Principle + MySQL Access Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Scoping agent tools and database accounts
To reduce risk with native controls, break large workflows into smaller parts. Do not attach one high-privilege MySQL tool sub-node to every AI agent in your workspace. Create distinct MySQL accounts for read-only reporting agents and write-heavy automation steps. Limit the columns and views that each MySQL account can read.
You can also use a Call n8n Workflow Tool to keep queries predictable. Instead of letting the agent write raw SQL, have it trigger a sub-workflow with fixed parameters. This keeps the AI Agent node from guessing table names or pulling whole tables at once. Even with these steps, native database grants still trust the stored login at runtime.
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 runs beside the database as a sidecar for your MySQL. It keeps your login setup and drivers as they are while checking queries on the wire.
With hoop.dev MySQL support, guardrails refuse bad queries before they run and return a readable MySQL error. 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 SQL Agent or a MySQL tool sub-node in n8n?
Use a MySQL tool sub-node attached to a current AI Agent node. From n8n 1.82.0, the old agent type setting is deprecated and all agents work as Tools Agents.
Can MySQL grants hide sensitive columns from an n8n AI agent?
MySQL supports column-level grants and views to block access to whole columns. Still, native grants cannot dynamically rewrite emails or card numbers inside allowed query results.
Why is one shared MySQL login risky for n8n workflows?
A shared login gives every workflow the top permission needed by any single task. It also hides which specific workflow or user ran a query in your MySQL logs.
Related guides
In this post