How to Configure Claude Code MariaDB Credentials

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up claude code mariadb credentials through the Model Context Protocol or shell tools. You should always pass a read-only database user in the connection string. Teams often put local database logins into agent config files to speed up work. When those roles have broad rights, an AI agent can change or delete live data. It can also pull sensitive customer rows into the model prompt window. How claude code mariadb credentials work in practice Claude Code reaches outside tools and databa

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 mariadb credentials through the Model Context Protocol or shell tools. You should always pass a read-only database user in the connection string. Teams often put local database logins into agent config files to speed up work. When those roles have broad rights, an AI agent can change or delete live data. It can also pull sensitive customer rows into the model prompt window.

How claude code mariadb credentials work in practice

Claude Code reaches outside tools and databases through the Model Context Protocol, known as MCP. Official vendor docs note that MCP servers let the agent query databases directly. You register an MCP database server and pass a standard database connection string. Vendor docs strongly advise using a read-only database user inside that connection string. This step makes sure the queries the agent runs cannot change your stored data.

The agent can also reach your database by running shell commands through its Bash tool. In manual mode, the Bash tool asks for your approval before running database client commands. Only a small built-in list of safe local file and git checks run without asking. Even with prompts, the Bash tool still uses whatever database password sits on your machine. The vendor docs also warn you to trust each MCP server before using it.

Creating a read-only role for your MariaDB user

Before you give the agent any login details, create a dedicated user inside MariaDB. Do not share your own admin account or the main app database login. Grant this new account only the right to read tables in specific database schemas. Never give this role permission to drop tables, change schemas, or write new rows.

You should also limit which network hosts this database user can log in from. If the agent runs on a developer laptop, bind the user to that network range. Set query time limits in MariaDB so a bad join cannot lock up your server. Once you verify these database rules, place the read-only login into your local setup. Keep the config file out of version control so teammates do not leak the secret.

Claude Code Security + Ephemeral Credentials: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native database roles solve and what they leave open

A read-only MariaDB user stops the agent from deleting rows or breaking table schemas. It also enforces basic login checks before any session starts from a developer machine. For local test databases with fake records, a read-only user is often enough.

Still, static database roles only check who logs in at the start of a session. They cannot inspect what individual SQL statements do while the session is running. A read-only user can still read every column inside an allowed production table by default. If a table holds emails, phone numbers, card numbers, or national IDs, queries return them. Those sensitive fields go straight into the AI model context window during debugging tasks. Also, storing long-lived database passwords on developer laptops creates a constant secret sprawl risk. Teams also lack a clear audit log tying each AI query to a specific person.

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 MariaDB database?

It connects through a Model Context Protocol server or by running shell commands in Bash. Both methods rely on a database connection string stored on the local machine.

Why should I use a read-only MariaDB user for AI agents?

An AI coding agent generates and runs SQL queries on its own during tasks. A read-only user ensures those automated queries cannot alter or delete your stored data.

Does a read-only MariaDB role protect sensitive customer columns?

No, a basic read-only role still lets queries pull every column in an allowed table by default. You need field masking to rewrite emails, phone numbers, and card numbers in query results.

The query runs. The emails stay hidden.