How to Configure Claude Code MySQL Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up claude code mysql permissions by creating a read-only database user first. Then you link the agent through a Model Context Protocol server or manual Bash tool. Many engineering teams start by handing the agent a standard local database account. That shortcut lets the agent alter schemas, delete rows, or read sensitive tables. When a prompt goes wrong, broad database roles turn small mistakes into real outages. Scoping down the database account is the first step toward safe agent workf

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 permissions by creating a read-only database user first. Then you link the agent through a Model Context Protocol server or manual Bash tool. Many engineering teams start by handing the agent a standard local database account. That shortcut lets the agent alter schemas, delete rows, or read sensitive tables. When a prompt goes wrong, broad database roles turn small mistakes into real outages. Scoping down the database account is the first step toward safe agent workflows.

How claude code mysql permissions work in practice

Claude Code reaches outside systems through two main paths. The first path uses Model Context Protocol servers to reach tools, databases, and APIs. Vendor docs highlight database queries as a core use case for this protocol. You pass a database string to the server so the agent can run queries. Vendor guidance tells you to use a read-only database user in that string. This rule ensures the queries the agent runs cannot change or delete your data. You should also verify that you trust any server before you use it.

The second path uses the built-in Bash tool to run shell commands. An agent can call a command line database client through this shell tool. In manual mode, the Bash tool asks for human approval before running most commands. Only a small built-in list of safe read-only commands runs without a prompt. When the agent tries to query a database via shell, you must approve it. Both paths rely on the underlying MySQL account to enforce hard database limits.

Why native database roles are only half the setup

Native MySQL roles do a great job of blocking unwanted writes at the engine level. A read-only user stops the agent from dropping tables or changing production records. You can grant select rights on specific tables and leave out secret schemas. This setup decides which account can log in and which tables it can read. For static apps with fixed queries, native database grants are often enough.

AI coding agents create new risks because they write and run ad hoc queries. A read-only role still lets the agent pull full tables of customer data. If a table holds emails, phone numbers, or card numbers, the query returns them. The database checks who logs in, not what each query returns in flight. Also, placing static database passwords in local agent files creates secret sprawl across laptops. Manual Bash prompts also slow down when engineers click approve without reading long queries. Teams need controls that inspect individual statements and rewrite sensitive fields in results.

Claude Code Security + MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Steps to lock down your agent database workflow

Start by creating a dedicated MySQL user just for your coding agent sessions. Grant this user select rights only on the non-sensitive tables needed for coding tasks. Never reuse an app service account or an admin login for an AI tool. Next, pick one clear path for the agent to reach the database. If you use a Model Context Protocol server, verify the server code first. Pass the read-only user credentials to that server and test a simple select query.

Keep the Bash tool in manual mode so shell commands require your explicit review. Check every database command the agent proposes before you let it run. Rotate the agent database password often and revoke the account when a project ends. Finally, pair these native grants with runtime controls that mask data like national IDs.

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?

The agent reaches databases through a Model Context Protocol server or its Bash tool. Both methods use the database user credentials you supply to run queries.

Why should I use a read-only MySQL user for an AI agent?

A read-only user stops the agent from running commands that change or delete data. Even if a prompt fails, the database engine blocks any write statements.

Does a read-only MySQL role hide sensitive customer fields?

No, a read-only role still returns all columns inside an allowed table by default. You need field-level masking to rewrite emails, phone numbers, or card numbers in results.

The query runs. The emails stay hidden.