Short answer: ChatGPT can't open a connection to MySQL by itself. Give it one through an app that only runs read-only SQL. With AI2SQL you add the database once with a SELECT-only user, install the AI2SQL app in ChatGPT, and sign in. The same steps work for Amazon RDS, Aurora MySQL, PlanetScale and MariaDB.
Step 1: a read-only MySQL user
Enforce read-only in MySQL itself, so a write fails even if every other layer missed it:
CREATE USER 'chatgpt_ro'@'%' IDENTIFIED BY 'a-long-random-password';
GRANT SELECT, SHOW VIEW ON appdb.* TO 'chatgpt_ro'@'%';
FLUSH PRIVILEGES;
To keep some tables out of reach, grant SELECT on chosen tables
(GRANT SELECT ON appdb.orders TO ...) instead of the whole database. Replace
% with AI2SQL's address range if your server restricts hosts.
Step 2: add the database to AI2SQL
Sign in at builder.ai2sql.io, open Connections, pick
MySQL and enter the host, port (usually 3306), database and the
chatgpt_ro user. If MySQL runs on your laptop (XAMPP, MAMP, Docker) or inside a
private network, use the desktop connector instead.
Step 3: install AI2SQL in ChatGPT
- Open the AI2SQL app in the ChatGPT plugin directory and add it.
- ChatGPT opens AI2SQL. Sign in with the account that holds the MySQL connection and press Allow.
- In a new chat, type @AI2SQL so ChatGPT uses the app for your question.
Prefer to add it by hand? Turn on developer mode in ChatGPT's connector settings and create a
connector with the URL https://builder.ai2sql.io/api/chatgpt-mcp and OAuth authentication.
Step 4: ask a question
Try "@AI2SQL describe my MySQL database, then show the 10 best-selling products this month."
ChatGPT reads the real schema with describe_schema, writes MySQL SQL
(DATE_FORMAT, LIMIT, backtick names) and runs it with
run_query. Ask ChatGPT to show the SQL it ran if you want to check it.
What keeps it safe
- Database level: the
chatgpt_rouser only hasSELECT. - Gateway level: one
SELECTorWITHstatement per call; writes, DDL,INTO OUTFILEand functions such asLOAD_FILE,SLEEPandBENCHMARKare rejected before they reach MySQL. - Limits: results are capped at 1,000 rows.
- No shared secrets: ChatGPT holds a revocable sign-in token, never the database password.
- Audit: every call appears in Agent activity with the SQL, the database and the result, including blocked attempts.
Common MySQL snags
- Access denied for user: the user was created for
localhostonly. Create it for%or for AI2SQL's address. - Can't connect to MySQL server:
bind-addressis127.0.0.1or port 3306 is closed. Open it for AI2SQL, or use the desktop connector for private networks. - Authentication plugin errors: on MySQL 8, create the user with
caching_sha2_password(the default) ormysql_native_passwordand try again.
The same connection also works from Claude. For PostgreSQL and SQL Server, see ChatGPT + PostgreSQL and ChatGPT + SQL Server.