MySQL MCP server

Provides secure MySQL database access for LLMs, enabling read/write operations with transaction support and security features for AI-assisted data management tasks.
Back to servers
Setup instructions
Provider
Kevin Watt
Release date
Feb 14, 2025
Language
TypeScript
Package
Stats
2.1K downloads
13 stars

This MCP server provides integration between MySQL databases and LLMs, allowing secure database access with both read and write capabilities through a standardized Model Context Protocol interface.

Installation

Install the MySQL MCP server using npm:

npm install -g @kevinwatt/mysql-mcp

Setting Up with Dive Desktop

Configuration Steps

  1. In Dive Desktop, click the "+ Add MCP Server" button
  2. Copy and paste the following configuration:
{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": [
        "-y",
        "@kevinwatt/mysql-mcp"
      ],
      "env": {
        "MYSQL_HOST": "127.0.0.1",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "root",
        "MYSQL_PASS": "",
        "MYSQL_DB": "your_database"
      }
    }
  }
}
  1. Update the environment variables with your MySQL database details
  2. Click "Save" to install and configure the MCP server

Available Tools

mysql_query

Execute read-only SELECT queries against your database.

Input Parameters:

  • sql (string): The SQL SELECT query to execute

Limitations:

  • Maximum query length: 4096 characters
  • Maximum result rows: 1000
  • Query timeout: 30 seconds

mysql_execute

Execute data modification operations with transaction support.

Input Parameters:

  • sql (string): SQL statement (INSERT/UPDATE/DELETE)
  • params (array, optional): Parameters for the SQL statement

Features:

  • Returns affected rows count
  • Returns last insert ID
  • Automatic transaction handling

list_tables

List all tables in the current database.

Input Parameters:

  • None required

describe_table

Show the structure of a specific table.

Input Parameters:

  • table (string): Name of the table to describe

Usage Examples

You can instruct your LLM to interact with the database using natural language. For example:

  • "Show me all tables in the database"
  • "Describe the structure of users table"
  • "Select all active users from the database"
  • "Insert a new record into orders table"

Starting Manually

If you need to start the server manually:

npx @kevinwatt/mysql-mcp

System Requirements

  • Node.js 18 or higher
  • MySQL Server
  • MCP-compatible LLM service

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "mysql" '{"command":"npx","args":["-y","@kevinwatt/mysql-mcp"],"env":{"MYSQL_HOST":"127.0.0.1","MYSQL_PORT":"3306","MYSQL_USER":"root","MYSQL_PASS":"","MYSQL_DB":"your_database"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "mysql": {
            "command": "npx",
            "args": [
                "-y",
                "@kevinwatt/mysql-mcp"
            ],
            "env": {
                "MYSQL_HOST": "127.0.0.1",
                "MYSQL_PORT": "3306",
                "MYSQL_USER": "root",
                "MYSQL_PASS": "",
                "MYSQL_DB": "your_database"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "mysql": {
            "command": "npx",
            "args": [
                "-y",
                "@kevinwatt/mysql-mcp"
            ],
            "env": {
                "MYSQL_HOST": "127.0.0.1",
                "MYSQL_PORT": "3306",
                "MYSQL_USER": "root",
                "MYSQL_PASS": "",
                "MYSQL_DB": "your_database"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later