MySQL Read-Only MCP server

Provides read-only access to MySQL databases for inspecting schemas and executing SQL queries without modifying underlying data.
Back to servers
Setup instructions
Provider
Ben Borla
Release date
Mar 18, 2025
Language
TypeScript
Stats
1 star

This MCP server for MySQL enables LLMs to inspect database schemas and execute read-only queries against MySQL databases. It provides a secure interface for language models to interact with your database while maintaining data security through read-only access.

Installation Options

Using Smithery

The easiest installation method is through Smithery:

# Install the MCP server
npx -y @smithery/cli@latest install @benborla29/mcp-server-mysql --client claude

Smithery will guide you through entering MySQL connection details and automatically set up environment variables, configure your LLM application, test the connection, and provide troubleshooting if needed.

Using MCP Get

You can also install via MCP Get:

npx @michaellatman/mcp-get@latest install @benborla29/mcp-server-mysql

Using NPM/PNPM

For manual installation:

# Using npm
npm install -g @benborla29/mcp-server-mysql

# Using pnpm
pnpm add -g @benborla29/mcp-server-mysql

Configuration

Automatic Configuration with Smithery

If you installed using Smithery, your configuration is already set up. View or modify it with:

smithery configure @benborla29/mcp-server-mysql

Manual Configuration for Claude Desktop App

To manually configure the MCP server, add the following to your claude_desktop_config.json file:

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

Replace db_name with your database name or leave it blank to access all databases.

Advanced Configuration Options

For more control over the server's behavior:

{
  "mcpServers": {
    "mcp_server_mysql": {
      "command": "/path/to/npx/binary/npx",
      "args": [
        "-y",
        "@benborla29/mcp-server-mysql"
      ],
      "env": {
        "MYSQL_HOST": "127.0.0.1",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "root",
        "MYSQL_PASS": "",
        "MYSQL_DB": "db_name",
        "PATH": "/path/to/node/bin:/usr/bin:/bin",
        
        "MYSQL_POOL_SIZE": "10",
        "MYSQL_QUERY_TIMEOUT": "30000",
        "MYSQL_CACHE_TTL": "60000",
        
        "MYSQL_RATE_LIMIT": "100",
        "MYSQL_MAX_QUERY_COMPLEXITY": "1000",
        "MYSQL_SSL": "true",
        
        "MYSQL_ENABLE_LOGGING": "true",
        "MYSQL_LOG_LEVEL": "info",
        "MYSQL_METRICS_ENABLED": "true"
      }
    }
  }
}

Environment Variables

Basic Connection

  • MYSQL_HOST: MySQL server host (default: "127.0.0.1")
  • MYSQL_PORT: MySQL server port (default: "3306")
  • MYSQL_USER: MySQL username (default: "root")
  • MYSQL_PASS: MySQL password
  • MYSQL_DB: Target database name

Performance Configuration

  • MYSQL_POOL_SIZE: Connection pool size (default: "10")
  • MYSQL_QUERY_TIMEOUT: Query timeout in milliseconds (default: "30000")
  • MYSQL_CACHE_TTL: Cache time-to-live in milliseconds (default: "60000")

Security Configuration

  • MYSQL_RATE_LIMIT: Maximum queries per minute (default: "100")
  • MYSQL_MAX_QUERY_COMPLEXITY: Maximum query complexity score (default: "1000")
  • MYSQL_SSL: Enable SSL/TLS encryption (default: "false")

Monitoring Configuration

  • MYSQL_ENABLE_LOGGING: Enable query logging (default: "false")
  • MYSQL_LOG_LEVEL: Logging level (default: "info")
  • MYSQL_METRICS_ENABLED: Enable performance metrics (default: "false")

Features and Capabilities

Tools

  • mysql_query
    • Execute read-only SQL queries against the connected database
    • All queries run within a READ ONLY transaction
    • Supports prepared statements for secure parameter handling
    • Configurable query timeouts and result pagination
    • Built-in query execution statistics

Resources

The server provides comprehensive database information:

  • Table Schemas
    • JSON schema information for each table
    • Column names and data types
    • Index information and constraints
    • Foreign key relationships
    • Table statistics and metrics
    • Automatically discovered from database metadata

Troubleshooting

Using Smithery for Troubleshooting

# Check the status of your MCP server
smithery status @benborla29/mcp-server-mysql

# Run diagnostics
smithery diagnose @benborla29/mcp-server-mysql

# View logs
smithery logs @benborla29/mcp-server-mysql

Using MCP Get for Troubleshooting

# Check the status
mcp-get status @benborla29/mcp-server-mysql

# View logs
mcp-get logs @benborla29/mcp-server-mysql

Common Issues

  1. Connection Issues

    • Verify MySQL server is running and accessible
    • Check credentials and permissions
    • Ensure SSL/TLS configuration is correct if enabled
    • Try connecting with a MySQL client to confirm access
  2. Performance Issues

    • Adjust connection pool size
    • Configure query timeout values
    • Enable query caching if needed
    • Check query complexity settings
    • Monitor server resource usage
  3. Path Resolution If you encounter "Could not connect to MCP server mcp-server-mysql", explicitly set the path:

    {
      "env": {
        "PATH": "/path/to/node/bin:/usr/bin:/bin"
      }
    }
    
  4. Authentication Issues

    • For MySQL 8.0+, ensure the server supports the caching_sha2_password authentication plugin
    • Check if your MySQL user is configured with the correct authentication method
    • Try creating a user with legacy authentication if needed:
      CREATE USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
      

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 "mcp_server_mysql" '{"command":"npx","args":["-y","@benborla29/mcp-server-mysql"],"env":{"MYSQL_HOST":"127.0.0.1","MYSQL_PORT":"3306","MYSQL_USER":"root","MYSQL_PASS":"","MYSQL_DB":"db_name"}}'

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": {
        "mcp_server_mysql": {
            "command": "npx",
            "args": [
                "-y",
                "@benborla29/mcp-server-mysql"
            ],
            "env": {
                "MYSQL_HOST": "127.0.0.1",
                "MYSQL_PORT": "3306",
                "MYSQL_USER": "root",
                "MYSQL_PASS": "",
                "MYSQL_DB": "db_name"
            }
        }
    }
}

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": {
        "mcp_server_mysql": {
            "command": "npx",
            "args": [
                "-y",
                "@benborla29/mcp-server-mysql"
            ],
            "env": {
                "MYSQL_HOST": "127.0.0.1",
                "MYSQL_PORT": "3306",
                "MYSQL_USER": "root",
                "MYSQL_PASS": "",
                "MYSQL_DB": "db_name"
            }
        }
    }
}

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