How to Configure LlamaIndex MySQL Credentials
You set up llamaindex mysql credentials by passing a SQLAlchemy database engine to the framework. This engine uses a MySQL user and password to log in and run generated SQL. Teams often start by using a shared admin login from a local file. That broad role lets an AI agent read every table or change live rows. A safe setup pairs a read-only MySQL role with a narrow table list. How llamaindex mysql credentials work in text-to-SQL LlamaIndex connects to relational data through a light wrapper a
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 credentials by passing a SQLAlchemy database engine to the framework. This engine uses a MySQL user and password to log in and run generated SQL. Teams often start by using a shared admin login from a local file. That broad role lets an AI agent read every table or change live rows. A safe setup pairs a read-only MySQL role with a narrow table list.
How llamaindex mysql credentials work in text-to-SQL
LlamaIndex connects to relational data through a light wrapper around SQLAlchemy. You build a SQLAlchemy engine first and pass your MySQL login details to it. Then you hand that engine to the LlamaIndex SQL database wrapper. When a user asks a question, the query engine builds a SQL statement. It sends that statement over the active MySQL session and reads the result.
During setup, you can name the exact tables the query engine should use. If you skip this list, the query engine pulls all schema context from MySQL. Pulling every table wastes prompt tokens and exposes hidden tables to the model. Naming specific tables keeps the prompt small and focused on relevant data.
The official docs note that running arbitrary SQL carries real security risks. The authors recommend restricted roles, read-only databases, and sandboxing for every text-to-SQL app. You should create a dedicated MySQL user that only has select privileges. Grant that user permissions on the few tables your app actually needs.
What native database roles solve and what they miss
A read-only MySQL role stops the agent from dropping tables or changing rows. It also blocks the app from reading tables outside its grant list. Storing the password in a secret manager keeps plain text keys out of code. These steps form a solid baseline for any database setup.
Still, database roles only check who logs in at the start of a session. They do not inspect individual SQL queries while they run in flight. Once the app logs in, it can read any column inside an allowed table. If a customer table holds emails, phone numbers, or card numbers, the query returns them. The language model receives those raw values and might put them in an answer.
Ephemeral Credentials + MySQL Access Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static credentials also create tracking problems for data teams. Every prompt from every user runs under the same shared MySQL service account. Database logs show the app role, not the person who asked the question. Also, a bad prompt can trigger a huge join across millions of rows. A read-only grant cannot stop a slow query from locking up CPU.
Steps to tighten your database setup
Start by creating a separate MySQL account just for your LlamaIndex app. Give this role select rights only on the tables needed for answers. If a table has private columns, create a safe SQL view instead. Grant the agent role select rights on the view, not the base table.
Next, always pass an explicit table list when you set up the query engine. This step stops the wrapper from scanning your whole database schema at startup. Set a query timeout on the MySQL user so bad joins fail fast. Finally, rotate the database key on a regular schedule to limit exposure.
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
How does LlamaIndex connect to a MySQL database?
LlamaIndex uses a light wrapper built on top of the SQLAlchemy library. You create a SQLAlchemy engine with your MySQL login details and pass it in.
What happens if I do not specify table names in the query engine?
If you leave out the table list, the engine pulls all schema context. This exposes every table the MySQL user can see to the language model.
Why is a read-only MySQL user not enough for AI agents?
A read-only user can still read sensitive columns like emails or card numbers. Data masking is needed to rewrite matched fields in results before the model reads them.
Related guides
In this post