How to Configure Claude Code MySQL Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up claude code mysql least privilege by giving the agent a read-only database user. You also restrict which Model Context Protocol servers and shell commands the agent can run. Many teams start by sharing their local developer database account with the coding agent. That account often holds full rights to alter tables, drop schemas, and write rows. When an AI tool uses broad rights, one bad query can break a shared database. Scoping the database account down to read-only access stops th

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 least privilege by giving the agent a read-only database user. You also restrict which Model Context Protocol servers and shell commands the agent can run.

Many teams start by sharing their local developer database account with the coding agent. That account often holds full rights to alter tables, drop schemas, and write rows. When an AI tool uses broad rights, one bad query can break a shared database. Scoping the database account down to read-only access stops the agent from changing data.

How claude code mysql least privilege works in practice

Claude Code reaches outside tools and databases in two main ways. First, it talks to external data sources through Model Context Protocol servers. Second, it runs local shell commands through its built-in Bash tool. Both paths need tight database rules so the agent only reads what it needs.

When you set up a database MCP server, you pass a connection string. The vendor docs for database access advise using a read-only database user in that string. With a read-only MySQL account, the queries the agent runs cannot modify your data. You should also verify that you trust each MCP server before you use it.

In MySQL, you build this setup by creating a dedicated role for the agent. You grant that role select rights only on the specific tables the task requires. You leave out insert, update, delete, and drop rights across every schema. Then you create a user for the agent and attach that limited role.

Next, you check how the agent uses its Bash tool on your machine. In manual mode, the Bash tool asks for your approval before running shell commands. Only a small built-in list of safe read-only commands runs without a prompt. If the agent tries to run a MySQL client command, you must check it first.

What native MySQL roles solve and what keeps the session active

Native MySQL permissions do a good job of stopping unintended writes and schema drops. If the coding agent generates a delete statement, the database engine blocks it right away. This simple step protects your tables from accidental edits during a fast coding session.

Least Privilege Principle + Claude Code Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, database user roles only decide who can log in and which tables open. They do not inspect what individual queries do in flight once the session starts. A read-only user with select rights on a customer table can still read every column by default. That query result might include emails, phone numbers, card numbers, or national IDs.

When the agent runs a broad select query, those fields flow into the model context. Native MySQL roles cannot rewrite matched fields in query results on the fly. They also tie permissions to a static password stored on the developer machine. Anyone or any script on that machine can reuse that connection string at any time.

Why query-level controls matter for AI agents

AI coding agents work fast and often run several queries to explore a schema. Static database users treat every select statement the same way once the login succeeds. Teams often need a way to inspect each statement before the database runs it. They also need a way to mask sensitive fields like emails or card numbers in results.

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

How does Claude Code connect to a MySQL database?

It connects through a Model Context Protocol server for databases or runs a CLI client through its Bash tool. Both methods use the database user credentials you supply on your machine.

Why does the documentation recommend a read-only database user?

A read-only user ensures that the queries the agent runs cannot modify or delete your data. Even if the model writes an unsafe update query, MySQL rejects the change.

Can a read-only MySQL role hide sensitive columns from the agent?

MySQL lets you grant select rights on specific columns, which blocks access to others completely. Still, native roles cannot dynamically rewrite matched fields like emails or phone numbers inside allowed columns.

The query runs. The emails stay hidden.