Skip to main content
← Back to Articles
mcpmysqldatabasecursorsqlsetup2026

MySQL MCP Server Setup for Cursor IDE (2026): Query Your Database from Chat

Connect MySQL to Cursor IDE with an MCP server so your AI can read schemas, write SQL, and debug slow queries without copy-pasting table structures. Includes a read-only user setup and mcp.json config.

By Web MCP GuideJuly 21, 20269 min read


MySQL MCP Server Setup for Cursor IDE (2026)

To connect MySQL to Cursor, add an mcpServers entry that points at a MySQL MCP server package with your connection details in the env block, then restart Cursor. Once it's running, your AI can inspect table structures, write queries against your real schema, and explain why a query is slow — instead of you pasting DESCRIBE output into chat by hand.

This is the same idea as the PostgreSQL MCP setup covered elsewhere on this site, adapted for MySQL/MariaDB's connection format and privilege model. If your team runs both engines, you'll end up with two nearly identical config blocks — one per database.

What the MySQL MCP Server Actually Gives You

Once connected, Cursor can typically:

  • List databases, tables, and views on the connection

  • Describe column names, types, keys, and indexes for a table

  • Run read queries and return results inline in chat

  • Cross-reference schema with your application code (models, migrations, ORM definitions)
  • Some community packages also support write queries (INSERT/UPDATE/DELETE) behind a confirmation flag. Treat that as an opt-in feature for local dev, not something you enable against a shared or production instance by default.

    When This Is Worth Setting Up (and When It Isn't)

    It's genuinely useful when you're writing migrations, debugging query performance, or explaining an unfamiliar schema to a new AI session. It's less useful — and a real risk — if you connect it directly to a production database with a high-privilege user. The MCP server executes whatever SQL the model constructs; a slightly ambiguous prompt plus a full-access credential is how you get an accidental table scan or a dropped index in the middle of a shift.

    Prerequisites


  • Cursor IDE 0.43+

  • Node.js 18+ installed

  • A running MySQL or MariaDB instance (local, RDS, PlanetScale, or similar)

  • Connection details: host, port, database name, and credentials for a dedicated MCP user (not your root/admin account)
  • Step 1: Create a Read-Only MySQL User

    Before touching your mcp.json, create a scoped-down user. This matters more for MySQL than it might seem, because the default root or app-service account usually has far more privilege than an AI assistant needs:

    CREATE USER 'mcp_reader'@'%' IDENTIFIED BY 'a-long-random-password';
    GRANT SELECT ON your_database.* TO 'mcp_reader'@'%';
    FLUSH PRIVILEGES;

    Swap '%' for a specific host or IP range if your MySQL server is reachable beyond localhost — leaving it open to any host is fine for a local dev instance, not for anything network-exposed.

    Step 2: Add the Server to Your MCP Config

    Open ~/.cursor/mcp.json (or Settings → MCP in Cursor) and add a mysql entry:

    {
    "mcpServers": {
    "mysql": {
    "command": "npx",
    "args": ["-y", "mysql-mcp-server"],
    "env": {
    "MYSQL_HOST": "127.0.0.1",
    "MYSQL_PORT": "3306",
    "MYSQL_USER": "mcp_reader",
    "MYSQL_PASSWORD": "a-long-random-password",
    "MYSQL_DATABASE": "your_database"
    }
    }
    }
    }

    Package names for MySQL MCP servers vary across the community more than for something like GitHub or Postgres — search npm for mysql-mcp or mcp-server-mysql and check the maintainer's last commit date before pinning one into a team config, since this corner of the ecosystem changes maintainers more often than the marquee integrations.

    Restart Cursor completely after saving the config.

    Step 3: Verify the Connection

    In Cursor chat, try:

    List the tables in this database

    Then follow up with something schema-specific:

    Describe the orders table — columns, types, and any foreign keys

    If you get real table and column names back, the connection is live. If you get an error, work through the troubleshooting section below before assuming the MCP config itself is wrong.

    Step 4: Practical Workflows

    Understand an unfamiliar schema

    Look at the users, accounts, and subscriptions tables and explain how they relate to each other

    Write a migration by describing the change in English

    The orders table needs a cancelled_at timestamp column and an index on (status, cancelled_at). Write the migration in the style of the other files in /db/migrations.

    The AI can check your existing migration files for naming conventions and match them, rather than guessing a generic format.

    Debug a slow query

    This query takes 4 seconds: [paste query]. Look at the table definitions and tell me what index would help, and show me the CREATE INDEX statement.

    Sanity-check data before a release

    Check the subscriptions table for rows where status = 'active' but expires_at is in the past — how many are there?

    Connecting to a Managed MySQL Instance

    For RDS, PlanetScale, or a similar managed provider, the config is the same shape with a different host and (usually) SSL requirements:

    {
    "mcpServers": {
    "mysql-prod-readonly": {
    "command": "npx",
    "args": ["-y", "mysql-mcp-server"],
    "env": {
    "MYSQL_HOST": "your-instance.region.rds.amazonaws.com",
    "MYSQL_PORT": "3306",
    "MYSQL_USER": "mcp_reader",
    "MYSQL_PASSWORD": "your-password",
    "MYSQL_DATABASE": "your_database",
    "MYSQL_SSL": "true"
    }
    }
    }
    }

    Name the connection entry something that signals its blast radius (mysql-prod-readonly, not just mysql) — when you're running several database connections at once, an ambiguous name is how someone runs a prompt against the wrong environment.

    PlanetScale note: PlanetScale enforces TLS by default and uses branch-based databases — point the MCP connection at a development branch, not main, if you want a safety net for anything experimental.

    Troubleshooting

    "Access denied for user" error
    Double-check the username and password in your env block match exactly what you created in Step 1 — copy-paste errors here are the most common cause. Also confirm the user's host mask ('%' vs 'localhost') actually covers where the MCP process is running from.

    "Can't connect to MySQL server"
    Verify the database is reachable from your machine: mysql -h HOST -P PORT -u mcp_reader -p in a terminal. If that fails, the problem is network/firewall access, not the MCP config.

    Server doesn't appear in Cursor after editing mcp.json
    Fully quit and reopen Cursor — a window reload isn't always enough to pick up new MCP entries. Then check View → Output → MCP for startup errors.

    Queries return truncated or missing results
    Some MySQL MCP packages cap result rows by default to avoid flooding the chat context. Ask for a narrower query (add a WHERE clause or LIMIT) rather than requesting an entire large table at once.

    SSL/TLS handshake errors against a managed database
    Managed providers (RDS, PlanetScale, Aiven) often require TLS. Set the SSL env var your package expects, or check whether it needs a CA certificate path rather than a boolean flag.

    Frequently Asked Questions

    Q: Is there an official MySQL MCP server, the way there's an official Postgres one?
    A: Not a single canonical one at the time of writing — this space is served by several community packages rather than one Anthropic-maintained reference server. Check npm activity and open issues before standardizing on a package for a team, and revisit that choice periodically since maintainership shifts.

    Q: Can the AI accidentally write to my database through this?
    A: Only if the user you configured has write privileges, or if you're running a package that explicitly enables write tools. The GRANT SELECT-only setup in Step 1 makes write queries fail at the database layer regardless of what the model attempts — that's a more reliable safeguard than trusting the MCP server's own confirmation prompts.

    Q: How is this different from just using MySQL Workbench or a GUI client alongside Cursor?
    A: A GUI client requires you to look something up and paste it into chat yourself. The MCP connection lets the AI look it up mid-conversation — while writing a migration, for example — without you switching windows. It's a convenience and context layer, not a replacement for a proper database client when you need to do serious manual exploration.

    Q: Does this work with MariaDB, or only MySQL proper?
    A: Most MySQL MCP packages use the standard MySQL wire protocol, which MariaDB also implements, so basic connectivity usually works. Vendor-specific features (some MariaDB-only functions or system tables) may not be covered — treat MariaDB support as "works for standard SQL," not "fully tested."

    Q: My queries are slow through MCP even though they're fast in my GUI client — why?
    A: Check whether the MCP server is opening a new connection per query instead of pooling. Some lightweight community packages don't pool connections, so each request pays a fresh TCP + auth handshake. If this matters for your workflow, look for a package that supports a persistent connection pool rather than switching databases to fix a client-side issue.

    Related Guides


  • PostgreSQL MCP Server Setup Guide

  • Supabase MCP Server: Cursor IDE Setup

  • MongoDB MCP Server: Cursor IDE Setup (2026)

  • How to Authenticate MCP Servers: OAuth & API Keys

  • Cursor IDE MCP Setup: Complete Guide (2026)
  • ---