How to Configure Codex MySQL Read Only Access
You set up codex mysql read only access by creating a database user with select privileges. You then give that user login key to the coding agent workspace. Many teams start by handing an agent their standard developer database login. That shortcut creates real risk when an automated tool runs a bad update or delete statement. A read-only database account blocks writes at the database engine level. It lets the agent inspect schemas and read rows without changing data. How to set up codex mysql
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 codex mysql read only access by creating a database user with select privileges. You then give that user login key to the coding agent workspace. Many teams start by handing an agent their standard developer database login. That shortcut creates real risk when an automated tool runs a bad update or delete statement. A read-only database account blocks writes at the database engine level. It lets the agent inspect schemas and read rows without changing data.
How to set up codex mysql read only access
Start inside your MySQL server by creating a dedicated user account for the coding agent. Grant this new account only select privileges on the specific schemas the agent needs to read. Do not grant insert, update, delete, drop, or alter permissions on any table. Leave out system tables and internal admin schemas from the grant scope.
Next, place the database host, port, user name, and password into the agent workspace settings. Coding agents reach databases either through shell database clients or through local tool integrations. When the agent runs a query, MySQL checks the user grants before reading any table. If the agent tries to change a row or drop a table, MySQL rejects the query right away. This simple role setup gives the agent safe visibility into table structures and sample rows.
Teams should also bind this MySQL user to specific source network addresses when possible. You can set resource limits on the account to cap the number of queries per hour. You can also limit how many concurrent database connections that user can open at once. These native database controls stop a runaway agent loop from exhausting all available server connections.
What native read-only roles solve and what they miss
A read-only MySQL user solves the problem of accidental data loss or schema changes. The database engine enforces this rule on every query, regardless of how the agent connects. Even if a prompt causes the agent to generate a delete statement, the data stays safe. For basic schema checks and query writing, a select-only role is a strong first step.
Still, a database grant only decides who can log in and which tables they can read. It does not inspect what individual select statements do while they run in flight. A read-only user can still select millions of rows in a single heavy query. That kind of unindexed join or full table scan can lock up a live database.
Auditor Read-Only Access + MySQL Access Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Native select privileges also return every column in a permitted table in plain text by default. If a customer table holds emails, phone numbers, card numbers, or national IDs, the query returns them. Those raw values then flow straight into the agent context window and third-party model logs. Shared static passwords in local config files also create secret sprawl across developer laptops. When a key leaks or an engineer leaves, rotating that password breaks every local setup. Teams also lack a clear audit trail that ties each database query to a specific person.
Why query-level controls matter for coding agents
AI coding agents work fast and run many queries to explore a database schema. They often sample tables to check data types, foreign keys, and edge cases. Relying only on static database grants forces an all-or-nothing choice on each table. Either the agent reads the whole table with all sensitive fields, or it gets no access.
To keep live data safe, teams need controls that work on each query in flight. Field masking rewrites matched fields like emails, phone numbers, and card numbers in query results. The agent still sees valid data shapes and column types, while sensitive values stay masked. Query logs tied to individual developer identities also show who ran which query and when.
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 sits inline in the wire protocol beside the database as a sidecar for your MySQL. On every production query an agent or engineer sends, hoop.dev decides to pass, mask, block, or escalate it for human review.
With hoop.dev MySQL support, guardrails refuse bad queries before they run or hold risky calls for approval, while 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 MySQL read-only user still slow down a database?
Yes, a read-only user can run large select queries, missing index scans, or expensive joins. These read queries can consume CPU and memory, which slows down the database for other apps. Setting account query limits and row caps helps reduce this load.
How does an AI coding agent connect to a MySQL database?
A coding agent usually connects through a local command line client or a tool server. It reads the database host and login credentials from local workspace settings or secret variables. Every query the agent runs uses the permissions of that configured MySQL user.
Does a read-only MySQL role protect sensitive customer columns?
No, standard MySQL table grants apply to whole tables or specific allowed columns. If a role has select permission on a column, MySQL returns the raw stored value. Protecting fields like emails or card numbers requires data masking on the query results.
Related guides
In this post