How to Configure LangChain MariaDB Read Only Access
You set up langchain mariadb read only access by creating a MariaDB user with select permissions only. Then you pass that user credential into the LangChain database connector in your app. Many teams start by reusing an existing app database account for their AI agent. That shortcut gives the language model full write and delete rights across production tables. A bad prompt or model mistake can then alter records or drop data. How to set up langchain mariadb read only access Start inside your
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 langchain mariadb read only access by creating a MariaDB user with select permissions only. Then you pass that user credential into the LangChain database connector in your app. Many teams start by reusing an existing app database account for their AI agent. That shortcut gives the language model full write and delete rights across production tables. A bad prompt or model mistake can then alter records or drop data.
How to set up langchain mariadb read only access
Start inside your MariaDB server before touching your Python or JavaScript code. Create a new database user dedicated only to your LangChain agent. Grant this new account the select right on the specific tables the agent needs. Do not grant insert, update, delete, drop, or alter rights on any schema. If the agent only needs three tables, do not grant select on the whole database.
Next, set up the database wrapper inside your LangChain app using that restricted user. The agent can understand natural language questions and convert them into SQL queries. It will then execute the queries and present the results to the user. In the wrapper options, list the included tables so the agent ignores other schemas. This keeps the prompt smaller and stops the model from guessing restricted table names.
What native MariaDB roles solve and what stays exposed
A read-only MariaDB user stops the agent from modifying rows or changing table structures. If the model writes a delete or update query, MariaDB blocks the statement right away. This database role is a required first step for any AI tool that runs SQL. It enforces a hard boundary at the storage engine level.
Still, a MariaDB role only checks who logs in and which tables they can read. It does not check what individual queries do in flight once the session starts. A read-only user can still run a massive join that locks up CPU and memory. Also, select rights on a customer table return every column in the result set. Sensitive fields like emails, phone numbers, card numbers, and national IDs flow straight into the model prompt. Finally, static database passwords stored in app config files are hard to rotate and audit per user.
Auditor Read-Only Access + Customer Support Access to Production: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Adding query limits and data controls for AI agents
To run agents safely in production, teams pair read-only roles with query timeouts and row limits. You can set resource limits on the MariaDB account to cap query run time. You can also create database views that leave out sensitive columns before granting select rights. Giving the agent access only to clean views keeps raw card numbers and emails out of results. When field masking is active, it rewrites matched fields in results before the app processes them. Clear audit logs that tie each generated query to a specific user request also help teams review agent behavior.
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 a LangChain prompt rule replace a read-only MariaDB user?
No, system prompts are instructions to the model, not security controls. A user can bypass prompt rules, so you must enforce read-only rights inside MariaDB.
How do I stop the agent from reading sensitive columns in a table?
Grant select rights on specific safe columns or create a filtered MariaDB view. You can also use a data masking layer that rewrites emails and card numbers in results.
What happens if the LangChain agent writes a slow query on MariaDB?
A read-only user can still run heavy select queries that slow down your server. Set statement timeouts and per-hour query limits on the MariaDB user to protect performance.
Related guides
In this post