AI Database Query Tools: How to Connect ChatGPT or Claude to Your Database
AI-powered database query tools let you ask a question in plain English and get rows back from your own database. This guide compares the three ways to do it (pasting a schema into a chat, a database IDE with AI, and an MCP connector) and walks through connecting ChatGPT or Claude to PostgreSQL, MySQL or SQL Server with read-only access.
Short answer: To let ChatGPT or Claude query your database, connect them through an MCP server that reads your schema and runs SQL read-only. With AI2SQL you add your database once in the AI2SQL dashboard, then add the AI2SQL connector in Claude or the AI2SQL plugin in ChatGPT and sign in. The assistant can then list your tables, write SQL against your real column names and return rows. Every query is a single SELECT or WITH statement; writes are rejected before they reach your database.
What AI Database Query Tools Do
An AI database query tool sits between a person (or an AI assistant) and a database. You describe what you want, for example "revenue by country last quarter", and the tool turns it into SQL, runs it and shows the result. The good ones do three things a plain chatbot cannot:
- Read the real schema. They know your table and column names, so the SQL uses
orders.created_atand not a guessedorder_date. - Run the query. You get rows, not just SQL you have to copy into another tool.
- Stay read-only. The tool can look, but it cannot update or delete anything.
The last point matters more once an AI assistant, not a person, is the one asking. An assistant may run several queries in a row without you reading each one first.
Three Ways to Query a Database With AI
1. Paste your schema into a chat
Copy your CREATE TABLE statements into ChatGPT or Claude and ask for SQL. It is free and needs no setup. The model only sees the snapshot you pasted, it cannot check that the columns still exist, and it cannot run anything. You copy the SQL into your own client and run it yourself. Fine for a one-off query, tiring for daily work.
2. A database IDE with an AI assistant
Tools such as DataGrip and DBeaver connect to your database and add an AI chat next to the SQL editor. The assistant sees your schema and you run the SQL in the same window. This suits developers and DBAs who already live in a database IDE. It does not help when the question starts in ChatGPT or Claude, and people who do not write SQL rarely install a desktop database client.
3. An MCP connector for ChatGPT, Claude and other assistants
The Model Context Protocol (MCP) lets an AI assistant call tools on a server. A database MCP server gives the assistant tools like "list connections", "describe schema" and "run query". The assistant reads the live schema, writes the SQL and runs it, all inside the chat. This is the only option where ChatGPT or Claude answers with real rows from your database.
You can run an open-source MCP server yourself, or use a hosted one. Self-hosting gives full control but means you run the server, store the database credentials and enforce read-only access yourself. A hosted server such as AI2SQL keeps the credentials encrypted on its side, signs the assistant in with OAuth and checks every statement before it runs.
| Paste schema into chat | Database IDE with AI | MCP connector | |
|---|---|---|---|
| Sees the live schema | No, a pasted copy | Yes | Yes |
| Runs the query | No | Yes, in the IDE | Yes, in the chat |
| Works inside ChatGPT or Claude | Yes | No | Yes |
| Read-only enforced | Up to you | Depends on the database login | Depends on the server; AI2SQL rejects anything but SELECT/WITH |
| Good fit for | One-off queries | Developers and DBAs | Analysts, founders, anyone asking questions in ChatGPT or Claude |
How to Connect Claude to Your Database
- Add your database to AI2SQL. Sign in at builder.ai2sql.io, open Databases and add a PostgreSQL, MySQL or SQL Server connection. Use a read-only database login (see security below). Databases on your own machine or behind a VPN go through the AI2SQL Connector desktop app.
- Add the connector in Claude. AI2SQL is in Claude's connector directory: open it, find AI2SQL and connect. Or add it as a custom connector with the URL
https://builder.ai2sql.io/api/claude-mcp. Custom connectors need Claude Pro, Max, Team or Enterprise. - Sign in. Claude opens an AI2SQL sign-in page (OAuth). Nothing else is pasted, no passwords and no API keys.
- Ask a question. For example: "Using AI2SQL, show the top 10 customers by revenue this year." Claude lists your connections, reads the schema, writes the SQL and runs it.
Claude Code, Cursor and VS Code (GitHub Copilot agent mode) connect to the same server; the setup for each is on the AI2SQL MCP page.
Want to try it before connecting anything? Create a free AI2SQL account and ask a question on the demo_shop sample database.
How to Connect ChatGPT to Your Database
- Add your database to AI2SQL, as in step 1 above.
- Install the AI2SQL plugin in ChatGPT. Find AI2SQL in ChatGPT's plugin directory and connect it. Developer mode is only needed if you want to add a custom server URL by hand.
- Sign in with your AI2SQL account.
- Ask a question. ChatGPT can describe your schema and run read-only SQL on the connections you set up.
What You Can Ask
Once connected, the assistant works with your real tables. Questions that work well:
- "Which products sold the most units last month, and what was the revenue for each?"
- "How many new customers signed up each week this quarter?"
- "Show orders over $500 that have not shipped yet."
- "Describe the tables related to invoices and how they join."
The assistant can also follow up on its own result: ask "now split that by country" and it writes a second query on the same tables.
Security: Read-Only Access, Masking and an Audit Log
Letting an AI assistant near a production database is a reasonable worry. Four layers keep it safe:
- A read-only database login. Create a user that can only
SELECTon the schemas the assistant needs. Even if everything else failed, the database itself refuses writes. - Statement checks on the server. AI2SQL's
run_queryaccepts a single SELECT or WITH statement. INSERT, UPDATE, DELETE, DDL and multi-statement batches are rejected before anything reaches your database, and results are capped at 1,000 rows. - Data masking. Turn on masking per column (placeholder, partial, hide or show). Names, emails and phone numbers are replaced on the AI2SQL server before results reach the assistant, so the real values never leave it.
- An activity log. Agent activity lists the calls from Claude, ChatGPT, Cursor and API keys with the exact SQL, the database, the result and the latency, including blocked write attempts.
For a deeper look at what read-only should block, see our guide to AI-generated SQL safety.
What It Costs
The AI2SQL Free plan includes 3 SQL queries a day on a demo database; connecting your own database is part of Pro and Team. Every plan can write SQL through the MCP server and try live queries on the demo_shop sample from Claude and ChatGPT. Running read-only queries on your own databases from Claude, ChatGPT, Cursor or VS Code is part of Pro ($19/month) and Team ($39/month). Each paid plan starts with a 7-day trial; a credit card is required to start it, and you pay nothing if you cancel before the 7 days end. (Plans checked 9 November 2026.)
Frequently Asked Questions
Can ChatGPT query my SQL database directly?
Not on its own. ChatGPT needs a connector that can reach the database. With the AI2SQL plugin, ChatGPT can describe your schema and run read-only SQL on PostgreSQL, MySQL or SQL Server connections you set up in AI2SQL.
Is it safe to connect Claude to a production database?
It can be, if access is read-only at two levels: a database login that can only SELECT, and a server that rejects anything but a single SELECT or WITH statement. Add column masking for personal data and keep an activity log of every query the assistant runs.
Which databases are supported?
Live schema and read-only queries work on PostgreSQL, MySQL and SQL Server connections. AI2SQL also writes SQL for Oracle, SQLite, Snowflake, BigQuery and other dialects without a live connection.
How is this different from pasting my schema into ChatGPT?
A pasted schema is a snapshot the model cannot verify or run. Through MCP the assistant reads the current schema itself, runs the query read-only and answers with real rows, and you never copy the schema anywhere.
Can I connect a database that runs on my own computer?
Yes. Databases on localhost or behind a VPN connect through the AI2SQL Connector desktop app, so the assistant can query them without exposing the database to the internet.