How to Configure n8n MariaDB Least Privilege
You set up n8n mariadb least privilege by creating a scoped database user for your workflow. Then you grant that user rights to only the exact tables and actions it needs. Many teams skip this step during early testing and use an admin account instead. That broad role lets a broken workflow or AI agent read or delete anything. If a workflow runs a bad query, it can wipe out production tables right away. Scoping the database account before you go live stops most of this damage. How to set up n8
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.
You set up n8n mariadb least privilege by creating a scoped database user for your workflow. Then you grant that user rights to only the exact tables and actions it needs. Many teams skip this step during early testing and use an admin account instead. That broad role lets a broken workflow or AI agent read or delete anything. If a workflow runs a bad query, it can wipe out production tables right away. Scoping the database account before you go live stops most of this damage.
How to set up n8n mariadb least privilege
First, list every database action your n8n workflow needs to run. Most workflows only need to read a few tables or add rows to one table. Some workflows run on a fixed path, while others use an AI Agent node. The n8n AI Agent node pairs a chat model with one or more tool sub-nodes. The agent then decides which tools to call to finish a task. For database tasks, n8n docs say to attach a MySQL tool sub-node to the agent. Since MariaDB works with the MySQL wire protocol, teams use this node for MariaDB too.
Next, log in to your MariaDB server as an admin to build a new user. Create a user account that only accepts logins from your n8n host network address. Do not give this user global rights across the whole database server. Grant only read rights on the specific tables the workflow or agent must check. If the workflow must save data, grant write rights on those target tables only. Never grant permissions to drop tables, change schemas, or manage other database users. Finally, save those new login details inside the n8n credential store for your node.
What native MariaDB roles solve and where they fall short
Native MariaDB roles do a great job of limiting where a user can log in. They also control which tables and columns that user can read or change. If an n8n workflow tries to drop a protected table, MariaDB blocks the action. This setup stops a bad workflow from destroying parts of the database it should not touch. It forms a strong base for database security that every team should use.
Still, static database roles only check who logs in and which table they touch. They cannot check what an individual SQL query does while it runs in flight. For example, a read-only user can still pull every row from a customer table by default. If that table holds emails, phone numbers, or card numbers, the query returns them all. An AI agent with read rights might send those raw national IDs to a chat model. Also, shared n8n credentials make it hard to see which person triggered a specific query. Static grants also cannot pause a risky update to ask a human for approval first.
Least Privilege Principle + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Why AI agent workflows need statement-level controls
From n8n version 1.82.0 onward, all AI Agent nodes run as a Tools Agent. The older agent type setting is deprecated and goes away in version 3.0. In this setup, the model writes and runs SQL queries based on user prompts. Even with a scoped MariaDB role, a prompt can trick the agent into reading sensitive rows. Database grants alone cannot rewrite matched fields in results to hide private data. Teams need a way to inspect each query and mask emails or card numbers on the fly.
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
Can n8n AI Agent nodes query MariaDB databases?
Yes, n8n AI Agent nodes can query MariaDB through a MySQL tool sub-node. You attach the tool sub-node to the agent and give it your scoped MariaDB login.
Should an n8n AI agent share a MariaDB user with other workflows?
No, you should create a separate MariaDB user just for the AI agent. Give that user read-only access to the exact tables and views the agent needs.
Does a read-only MariaDB user stop private data leaks in n8n?
No, a read-only role still lets queries return raw emails, phone numbers, and card numbers. You need data masking in flight to rewrite matched fields in results before n8n gets them.
Related guides
In this post