How to Configure LlamaIndex MySQL Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up llamaindex mysql permissions by making a read-only database user for your app. Then you pass that user key to the SQLAlchemy wrapper and name allowed tables. Many teams start by reusing an admin account during early testing. That fast shortcut lets a text-to-SQL prompt read, change, or drop every table in your database. How llamaindex mysql permissions work in practice LlamaIndex connects to relational databases through a light wrapper around SQLAlchemy. You pass a standard databas

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 llamaindex mysql permissions by making a read-only database user for your app. Then you pass that user key to the SQLAlchemy wrapper and name allowed tables. Many teams start by reusing an admin account during early testing. That fast shortcut lets a text-to-SQL prompt read, change, or drop every table in your database.

How llamaindex mysql permissions work in practice

LlamaIndex connects to relational databases through a light wrapper around SQLAlchemy. You pass a standard database string into this wrapper when your app starts. Next, the natural language table query engine turns user questions into SQL queries. The engine then runs those generated queries right on your MySQL server.

If you do not pass a table list, the engine pulls all schema context. It reads every table name and column in the database to build its prompt. This wastes context tokens and exposes internal tables to the language model. Naming specific tables in the engine setup keeps the schema prompt small and focused.

Still, an engine table list is not a real database boundary. The official LlamaIndex docs warn that running arbitrary SQL queries is a security risk. They advise teams to use restricted roles, read-only databases, and sandboxing. In MySQL, this means creating a dedicated user account just for your AI agent.

You grant this MySQL user select privileges on the exact tables the agent needs. You leave out insert, update, delete, and drop privileges on every schema. When the model writes a bad update statement, MySQL blocks it right away.

How to scope table and column grants in MySQL

Start by listing the exact business questions your text-to-SQL app needs to answer. Pick only the tables required to answer those specific user questions. In MySQL, you can grant select access at the table level or column level. Column grants let you share a customer table while leaving out password hash columns.

You can also build read-only SQL views for the agent to query. A view joins complex tables ahead of time and hides internal system columns. You then grant the MySQL user select access only on those safe views. This keeps generated queries simple and stops the model from scanning raw tables.

MySQL Access Governance + AI Agent Permissions: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Teams also set MySQL resource limits on the agent user account. A bad prompt can trick the model into writing a huge cross join. Setting query timeouts and row limits helps protect database memory and CPU.

What native database roles solve and what they miss

Native MySQL grants are great at deciding who can log in to the database. They also enforce which tables and columns that account can read or write. If a generated query tries to delete a table, the database stops it cold.

Yet static database roles cannot inspect what individual queries do in flight. A read-only user still needs select access to customer tables to do its job. Once a table is readable, any query from that user returns raw rows. Static grants cannot mask emails, phone numbers, card numbers, or national IDs in results.

Database roles also share one static identity across all your app users. When ten people ask questions through the app, MySQL sees just one account. Audit logs show the shared app user rather than the person who asked. Finally, storing raw database keys in app files creates a constant secret leak risk.

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. It runs next to MySQL, RDS, or Aurora and reads the MySQL wire protocol.

Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails. When a rule refuses a query, MySQL returns a native error packet with your message. On the response path, hoop.dev data masking rewrites string values in returned rows that match your rules. Every query and decision is logged per resource. See the MIT-licensed project on GitHub.

Frequently asked questions

Does the LlamaIndex table list stop unauthorized SQL queries?

No, naming tables in the query engine only limits the schema context sent to the model. The model can still write a query against other tables if it guesses their names. You must enforce table limits inside MySQL using restricted user grants.

What privileges should a LlamaIndex MySQL user have?

Give the MySQL user only the select privilege on the specific tables or views it needs. Never grant insert, update, delete, drop, or alter privileges to a text-to-SQL account. You can also restrict select access to specific safe columns inside a table.

How do you handle sensitive fields in text-to-SQL results?

You can exclude sensitive columns using MySQL column grants or custom SQL views. If the query still needs those columns, use dynamic data masking to rewrite matched fields in results. This replaces emails, phone numbers, or card numbers before the model reads the output.

The query runs. The emails stay hidden.