How to Configure Claude Code MySQL Read Only Access
You set up claude code mysql read only access with a select-only database user. You then pass that user's connection string to the agent through an MCP server. Teams often start by handing an agent their normal dev login. That broad role lets a bad query change rows or drop tables by mistake. A dedicated read-only user blocks writes at the database engine level. How claude code mysql read only access works in practice Claude Code reaches outside systems in two main ways. First, it uses the Mo
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 claude code mysql read only access with a select-only database user. You then pass that user's connection string to the agent through an MCP server. Teams often start by handing an agent their normal dev login. That broad role lets a bad query change rows or drop tables by mistake. A dedicated read-only user blocks writes at the database engine level.
How claude code mysql read only access works in practice
Claude Code reaches outside systems in two main ways. First, it uses the Model Context Protocol, also known as MCP. MCP servers give the agent a path to your tools, databases, and APIs. Vendor docs list database queries as a core MCP use case. Their example uses the DBHub MCP server with a database connection string. Those docs tell you to put a read-only database user in that string. That way, the queries the agent runs cannot change your data.
Second, the agent can run shell commands through its built-in Bash tool. In Manual mode, the Bash tool asks for your approval before it runs commands. Only a small built-in list of safe read commands runs without a prompt. If a developer approves a database CLI command, the agent uses local shell credentials. To keep both paths safe, you must create a strict MySQL role first.
Inside MySQL, an admin creates a dedicated account just for the coding agent. The admin grants only the select privilege on the target schemas and tables. They leave out insert, update, delete, alter, and drop rights. Next, the developer puts that read-only login into the MCP server connection string. They also use that same restricted account for any local MySQL client profiles. The vendor docs warn you to check that you trust each MCP server first. A local MCP server runs on your machine with your user permissions.
What native read-only roles solve and what they miss
A select-only MySQL account is a strong first step for any team. It stops the coding agent from changing records or dropping a table. Even if the model invents a delete statement, MySQL blocks the query right away. This setup is simple to build and uses native database roles.
Still, a database login only checks who logs in at the start. It does not inspect what individual queries do while they run. A read-only user can still read every column in an allowed table by default. When the agent runs a query, the database sends back raw rows. Those rows might hold emails, phone numbers, card numbers, or national IDs. Once the MCP server returns those rows, they enter the model prompt context. Native MySQL roles do not rewrite matched fields in query results on the fly.
Auditor Read-Only Access + Claude Code Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static connection strings on laptops also create key management work for your team. Every developer stores the database password in a local MCP config file. If that password leaks, you must rotate it across every machine. A read-only role also cannot stop a bad join that scans millions of rows. You still need a way to inspect queries and mask sensitive fields in flight.
Keeping local agent configs clean and safe
Teams should treat coding agents like any other automated database client. Give the agent its own MySQL user so its queries show up in logs. Do not share personal admin logins with an MCP server or shell script. Scope the select grant down to the exact tables the developer needs today. Leave sensitive billing or auth tables out of the grant when you can. Review the MCP servers on each laptop and keep their settings in version control without secrets.
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, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.
Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.
Frequently asked questions
How does Claude Code connect to a MySQL database?
It connects through an MCP server such as DBHub or through its Bash tool. The MCP server takes a connection string and runs queries for the agent.
Why does a read-only MySQL user still expose sensitive data?
A select grant lets the user read all columns in an allowed table by default. The database returns raw emails, phone numbers, and card numbers to the agent context.
Does the Bash tool run database commands without asking?
No, in Manual mode the Bash tool asks for approval before running database commands. Only a small built-in set of basic file and git read commands runs by default.
Related guides
In this post