Connect MySQL to Cursor with MCP (Step-by-Step)
Connect Cursor to MySQL through a hosted MCP server. Create a restricted user, configure mcp.json, verify schema access, and test denied writes.
The short answer
To connect Cursor to MySQL through MCP without putting the database password in Cursor:
- create a dedicated MySQL user with the minimum required grants
- add that MySQL connection to datamcp
- create a read-only MCP link
- put the hosted URL and MCP credential in
.cursor/mcp.json - verify schema discovery, an allowed
SELECT, and a denied write
Cursor receives database tools through the MCP link. The MySQL credential stays on datamcp, and the effective access remains bounded by both the MCP-link policy and MySQL grants.
If you are still choosing a runtime, start with the MySQL MCP server overview or the MySQL MCP server comparison.
For a reusable database-boundary template, use the MySQL AI access security kit. It covers a host-scoped account, TLS, explicit table grants, effective-account checks, denial tests, and emergency revocation.
What Cursor gets from a MySQL MCP server
A database MCP server lets Cursor request structured context instead of guessing your schema. The MySQL connection can expose tools to:
- inspect tables and views
- inspect columns, primary keys, foreign keys, and indexes
- get details for one table
- execute SQL allowed by the link and database account
- inspect the current MCP permission scope
- refresh schema context after a database change
MCP does not make generated SQL safe by itself. Client authentication, link policy, MySQL grants, network exposure, TLS, result handling, and review still matter.
1. Create a dedicated MySQL user
Do not connect an AI client with root, a migration owner, or an application account that has broader privileges than the workflow requires.
For a read-only starting point:
CREATE USER 'cursor_reader'@'%' IDENTIFIED BY 'use-a-long-generated-password';
GRANT SELECT ON app_database.* TO 'cursor_reader'@'%';
SHOW GRANTS FOR 'cursor_reader'@'%';
Replace % with the narrowest host rule that works with your deployment. If your managed MySQL provider uses a different user or network model, follow that provider's access controls rather than copying the example blindly.
For write workflows, grant only the operations the task needs. For example:
GRANT SELECT, INSERT, UPDATE ON app_database.* TO 'cursor_writer'@'%';
Avoid granting DROP, ALTER, CREATE USER, GRANT OPTION, or global privileges for ordinary coding assistance.
2. Require encrypted transport where available
Use your provider's verified TLS configuration. Do not disable certificate verification only to make the first test pass. A hosted MCP layer protects the credential from being copied into Cursor, but the datamcp-to-MySQL connection still needs an appropriate network and TLS boundary.
Your connection URL normally follows this shape:
mysql://cursor_reader:password@db.example.com:3306/app_database
Percent-encode special characters in the username or password when they appear inside a URL.
3. Add the MySQL connection to datamcp
Go to dashboard.datamcp.app, choose Add Connection, and select MySQL.
Add the connection URL or enter the host, port, database, username, password, and TLS settings. Test the connection before saving it. datamcp then reads the database metadata needed for schema tools.
The MySQL credential is encrypted at rest and remains on the connection. It is not copied into Cursor's configuration.
4. Create a read-only MCP link
Create a new MCP link for Cursor and start with Read Only.
Treat the final permission as an intersection:
Cursor user access
∩ MCP client authentication
∩ DataMCP link policy
∩ MySQL account grants
= effective access
The database account should still be restricted even when the MCP link is read-only. That protects the database if a configuration mistake later broadens one layer.
Use a separate link for each person or client when independent revocation or permissions matter.
5. Configure Cursor mcp.json
Copy the configuration shown in the datamcp setup guide into the project-level .cursor/mcp.json or your global Cursor MCP configuration:
{
"mcpServers": {
"app-mysql": {
"url": "https://api.datamcp.app/api/mcp/YOUR_CONNECTION_ID",
"headers": {
"Authorization": "Bearer sk_live_YOUR_API_KEY"
}
}
}
}
Use the exact URL and credential generated for your link. Do not paste the MySQL connection string into this file.
Restart or reload Cursor after changing the configuration. Confirm that the server appears in Cursor's MCP settings before testing it in chat.
6. Verify schema discovery
Ask Cursor:
List the available MySQL tables, then describe the columns, keys, and indexes on the orders table. Do not run a query yet.
Check that:
- real table names appear
- the selected database is correct
- keys and relationships match the current schema
- sensitive or irrelevant tables are not unexpectedly available
If the expected table is missing, verify the selected database and the account's metadata access before broadening SQL privileges.
7. Test an allowed query
Use a bounded read:
Show five recent orders with only order ID, status, and created timestamp. Do not return customer contact details.
Review the generated SQL before treating the result as trustworthy. A row limit reduces accidental volume but does not determine whether the selected columns are appropriate to expose.
8. Test a denied write
Ask Cursor to attempt a harmless write against a disposable target, or inspect the planned query without executing it. The important result is that the read-only boundary rejects INSERT, UPDATE, DELETE, and DDL.
If a write succeeds unexpectedly:
- disable or delete the MCP link
- inspect the link policy
- inspect
SHOW GRANTSfor the MySQL user - rotate the MCP credential if it was shared
- repeat both the allowed and denied tests
Do not move a link to read-write until the workflow has a concrete write requirement and a rollback plan.
Local MySQL MCP server vs hosted link
| Requirement | Local MySQL MCP | Hosted datamcp link |
|---|---|---|
| Runtime | Process on the developer machine | Hosted HTTPS endpoint |
| MySQL credential | Usually local config or environment | Kept on datamcp |
| Sharing | Repeat setup per machine | Create separately authenticated links |
| Revocation | Rotate or edit local configuration | Delete one MCP link |
| Best fit | One developer and a local database | Shared or remote database access with central policy |
A local server may be the right choice for a disposable development database and one trusted machine. A hosted endpoint is useful when the database is already remote or several clients need access without receiving the database password.
Troubleshooting Cursor and MySQL MCP
Cursor does not show the server
- validate the JSON syntax
- verify whether you edited the project or global configuration
- reload Cursor
- confirm that the hosted URL and authorization header came from the same MCP link
Authentication fails
The MCP API key authenticates Cursor to datamcp. It is not the MySQL password. Rotate the link credential if it was copied into an issue, chat, or repository.
MySQL connection fails
- confirm host, port
3306unless your provider uses another port, and database name - confirm the provider allows the hosted connection path
- verify the username host rule
- use the provider's correct TLS mode and CA requirements
- test with the same restricted account rather than an administrator account
Schema is incomplete
Confirm that the connection targets the expected database and that the MySQL user can inspect the relevant objects. Do not solve a metadata issue by immediately granting global privileges.
Queries are denied
A denial may come from the MCP-link policy or MySQL grants. Keep both boundaries visible and grant only the missing operation on the required schema or table.
Production checklist
- dedicated MySQL account, not
root - narrow schema and operation grants
- verified TLS where supported
- read-only MCP link first
- separate link for independent revocation
- schema output reviewed
- allowed read tested
- denied write tested
- no secrets committed in
.cursor/mcp.json - query activity reviewed after setup
For the compact product reference, continue with the MySQL MCP server page and MySQL documentation.
Related articles
Best MySQL MCP Servers in 2026 (Compared)
Compare MySQL MCP servers for Cursor and Claude: local Node and Python projects, multi-database DBHub, and hosted datamcp access.
TutorialConnect Cursor to PostgreSQL with MCP (Step-by-Step)
Connect Cursor to PostgreSQL through a hosted MCP link. Configure mcp.json, start read-only, verify schema tools, and test database access.
Want to test hosted MySQL MCP?
Connect one MySQL source and create one scoped MCP link on the Free plan.
Create MySQL MCP linkExplore MySQL MCP · Questions? Read the docs or view pricing.