Connect Claude to MySQL, read-only

Add your MySQL database to AI2SQL, add the AI2SQL connector to Claude, and sign in. Claude can then read your schema and run SELECT queries, while writes are blocked and your password never leaves AI2SQL.

Short answer: the safe way to connect Claude to MySQL is through an MCP server that only runs read-only SQL, using a MySQL user that can only SELECT. With AI2SQL you add the database once, add the AI2SQL connector to Claude (https://builder.ai2sql.io/api/claude-mcp), and sign in. Nothing goes into a config file that could leak your password.

Step 1: create a read-only MySQL user

Don't rely on the AI to behave. Make writes impossible in the database itself. Replace shop with your database name:

CREATE USER 'claude_ro'@'%' IDENTIFIED BY 'a-long-random-password';
GRANT SELECT, SHOW VIEW ON shop.* TO 'claude_ro'@'%';
FLUSH PRIVILEGES;

To keep Claude away from sensitive tables, grant SELECT on specific tables (shop.orders, shop.products) instead of shop.*. A read replica is even better for a busy production database.

Step 2: add the database to AI2SQL

Sign in at builder.ai2sql.io, open Connections, pick MySQL and enter the host, port, database and the claude_ro user. The connection test runs before saving. If MySQL only listens on localhost or a private network, use the desktop connector.

Step 3: add the AI2SQL connector to Claude

claude.ai or Claude Desktop

  1. Open Customize → Connectors.
  2. Add AI2SQL from the directory, or choose Add custom connector and paste the URL below.
  3. Press Connect, sign in to AI2SQL and press Allow.
https://builder.ai2sql.io/api/claude-mcp

Custom connectors need Claude Pro, Max, Team or Enterprise.

Claude Code

claude mcp add --transport http ai2sql https://builder.ai2sql.io/api/claude-mcp

Then run /mcp, pick ai2sql and choose Authenticate.

Step 4: ask a question

Try "Use AI2SQL to describe my MySQL database and show the 10 customers with the most orders this month." Claude calls describe_schema to read your real tables, writes the query, and runs it with run_query. No database yet? Ask about demo_shop, a sample store that works on every plan.

What keeps it read-only

More on the risks and how each layer handles them: is it safe to connect AI to your production database?

Frequently asked

How do I connect Claude to a MySQL database? +

Add your MySQL database in AI2SQL (Connections, MySQL), then add the AI2SQL connector to Claude: in claude.ai or Claude Desktop under Customize, Connectors (custom connector URL https://builder.ai2sql.io/api/claude-mcp), or in Claude Code with claude mcp add --transport http ai2sql https://builder.ai2sql.io/api/claude-mcp. Sign in with OAuth and Claude can read your schema and run read-only SQL.

Can Claude change or delete data in my MySQL database? +

Not through AI2SQL. run_query accepts one SELECT or WITH statement and rejects INSERT, UPDATE, DELETE and DDL before they reach MySQL. For a second layer, connect with a MySQL user that only has SELECT, so the database itself refuses writes.

Do I put my MySQL password in Claude's config? +

No. The password is entered once in AI2SQL, where it is encrypted. Claude signs in to AI2SQL with OAuth and only holds a token you can revoke.

Does it work with MariaDB, Amazon RDS, Aurora MySQL or PlanetScale? +

Any MySQL-compatible server that AI2SQL can reach over the network works the same way. A database on localhost or a private network needs the AI2SQL desktop connector instead.

What does it cost? +

Signing in, listing connections, reading schemas, the demo_shop sample and a few SQL writing requests a day are free. Running queries on your own database needs Pro or Team, which start with a 7-day trial.

Let Claude answer from your MySQL data

Connect MySQL, add one connector, sign in. Read-only and logged from the first query.

Connect MySQL free →

Related guides