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
- Open Customize → Connectors.
- Add AI2SQL from the directory, or choose Add custom connector and paste the URL below.
- 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
- Database level: the
claude_rouser can onlySELECT, so MySQL itself refuses writes. - Gateway level: AI2SQL accepts one
SELECTorWITHstatement per call and rejectsINSERT,UPDATE,DELETEand DDL before they reach MySQL. - Limits: results are capped at 1,000 rows.
- No shared secrets: Claude holds a revocable OAuth token, never the MySQL password.
- Audit: every call appears in Agent activity with the SQL, the database and the result.
More on the risks and how each layer handles them: is it safe to connect AI to your production database?