How to Configure LlamaIndex MariaDB Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up llamaindex mariadb read only access, create a restricted database user with select privileges. Then connect your query engine using that restricted database account and explicit table lists. Many engineering teams start by handing an agent a standard app login. That approach creates serious danger because the query engine runs generated SQL statements directly. If a user prompt tricks the model, a broad account can change or delete production tables. How llamaindex mariadb read only

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 llamaindex mariadb read only access, create a restricted database user with select privileges. Then connect your query engine using that restricted database account and explicit table lists. Many engineering teams start by handing an agent a standard app login. That approach creates serious danger because the query engine runs generated SQL statements directly. If a user prompt tricks the model, a broad account can change or delete production tables.

How llamaindex mariadb read only access works in practice

LlamaIndex connects to relational databases through a light wrapper around SQLAlchemy. You pass a database engine into this wrapper to link your MariaDB server. Next, the natural language query engine turns user questions into SQL queries. It runs those generated queries against the tables you specify during setup. If you do not name specific tables, the query engine pulls all schema context. Loading the whole schema wastes context tokens and exposes internal tables to the model.

Official LlamaIndex docs notes that running arbitrary SQL queries is a security risk. The authors recommend using restricted roles, read-only databases, and sandboxing to lower this risk. On the MariaDB side, you set up a dedicated account for the AI app. You grant this database account select permissions only on the required tables or views. You also leave out permissions for data changes, schema edits, and user management. When the query engine sends a write command, MariaDB blocks the action right away.

What native database roles solve and what they leave open

A read-only MariaDB user stops accidental or hostile writes from changing your stored data. It also limits which schemas the query engine can inspect when building prompts. This basic database role setup is a mandatory first step for any text-to-SQL deployment. Still, database roles only check who logs in and which tables they can read. They do not inspect what individual statements do in flight or filter returned rows.

Even with read-only permissions, a generated query can read sensitive customer columns. For example, a select statement might pull emails, phone numbers, card numbers, or national IDs. Without field-level rewriting, those raw values flow straight into the language model prompt. A read-only user can also run heavy joins that lock up database memory and CPU. Also, shared database logins make audit logs hard to trace back to people. Every query in the MariaDB log shows the same shared app account name.

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.

Reducing schema exposure and runtime query risk

Teams can tighten their setup further by pairing restricted roles with strict table lists. Always define the exact table names when you build the LlamaIndex database wrapper. This simple step stops the framework from reading every table definition in your schema. You can also create dedicated MariaDB views that leave out secret columns. Grant your AI database user select permissions on those safe views instead of base tables.

Database admins should also set resource limits on the MariaDB account used by the app. Setting query timeouts and connection limits helps stop bad queries from taking down the server. Still, managing views for every new AI feature takes time and constant database changes. Teams need a way to inspect queries, mask sensitive fields, and log user identities centrally.

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

Why does LlamaIndex pull the entire MariaDB schema by default?

When you do not list target tables, the query engine pulls all schema context by default. Passing a strict list of table names keeps the prompt small and hides private tables.

Can a read-only MariaDB role stop sensitive data leaks into prompts?

No, a read-only role still lets queries read every column inside an allowed table by default. Unless you use restricted views or data masking, emails and card numbers reach the model.

How does LlamaIndex connect to a MariaDB database?

The framework uses a light wrapper around SQLAlchemy to manage database connections and inspect schemas. You provide a standard SQLAlchemy engine configured for your MariaDB host and read-only user.

The query runs. The emails stay hidden.