Back to MCP Catalog

MySQL Database Access MCP Server

DatabasesTypeScript
Access and query MySQL databases with read-only or write capabilities
Available Tools

getSchemas

Retrieves all available database schemas

getTables

Lists all tables in a specific schema

getTableInfo

Gets detailed information about a specific table including columns and constraints

executeQuery

Executes a read-only SQL query against the database

executeInsert

Executes an INSERT SQL statement (when enabled)

executeUpdate

Executes an UPDATE SQL statement (when enabled)

executeDelete

Executes a DELETE SQL statement (when enabled)

switchDatabase

Switches to a different database in multi-DB mode

MySQL Database Access provides a secure interface for AI assistants to interact with MySQL databases. It enables database schema inspection and SQL query execution with configurable permission levels. This MCP server supports both read-only and write operations (optional), allowing AI assistants to retrieve data, analyze database structures, and even modify data when properly configured. With multi-database support and schema-specific permissions, it offers flexible and secure database access tailored to your needs.

Overview

The MySQL Database Access MCP enables AI assistants to interact with MySQL databases, providing capabilities to inspect database schemas and execute SQL queries. It supports both read-only and write operations (when enabled), making it a powerful tool for database exploration and management.

Installation Options

Using NPX (Recommended)

The simplest way to install and run the MySQL Database Access MCP is using NPX:

npx -y @benborla29/mcp-server-mysql

Using Smithery

You can install this MCP through Smithery with:

smithery install @benborla29/mcp-server-mysql

Using MCP Get

Install with MCP Get using:

mcp-get install @benborla29/mcp-server-mysql

Manual Installation

To install from the repository:

  1. Clone the repository:

    git clone https://github.com/benborla/mcp-server-mysql.git
    
  2. Navigate to the directory:

    cd mcp-server-mysql
    
  3. Install dependencies:

    npm install
    
  4. Start the server:

    npm start
    

Configuration

Environment Variables

Create a .env file in the root directory with the following variables:

MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=your_username
MYSQL_PASS=your_password
MYSQL_DB=your_database
ALLOW_INSERT_OPERATION=false
ALLOW_UPDATE_OPERATION=false
ALLOW_DELETE_OPERATION=false

Write Operations

By default, all write operations (INSERT, UPDATE, DELETE) are disabled for security. To enable them, set the corresponding environment variables to true:

ALLOW_INSERT_OPERATION=true
ALLOW_UPDATE_OPERATION=true
ALLOW_DELETE_OPERATION=true

Multi-Database Mode

The MCP supports connecting to multiple databases. To enable this mode:

  1. Set MULTI_DB_MODE=true in your environment variables
  2. Create a databases.json file in the root directory with your database configurations:
[
  {
    "id": "db1",
    "host": "localhost",
    "port": 3306,
    "user": "user1",
    "password": "password1",
    "database": "database1",
    "allowInsert": false,
    "allowUpdate": false,
    "allowDelete": false
  },
  {
    "id": "db2",
    "host": "localhost",
    "port": 3306,
    "user": "user2",
    "password": "password2",
    "database": "database2",
    "allowInsert": true,
    "allowUpdate": false,
    "allowDelete": false
  }
]

Schema-Specific Permissions

You can configure permissions for specific schemas by adding a permissions.json file:

{
  "schemas": {
    "public": {
      "tables": {
        "users": {
          "allowSelect": true,
          "allowInsert": false,
          "allowUpdate": false,
          "allowDelete": false
        }
      }
    }
  }
}

Client Configuration

Claude Desktop

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": "your_username",
        "MYSQL_PASS": "your_password",
        "MYSQL_DB": "your_database",
        "ALLOW_INSERT_OPERATION": "false",
        "ALLOW_UPDATE_OPERATION": "false",
        "ALLOW_DELETE_OPERATION": "false",
        "PATH": "/path/to/node/bin:/usr/bin:/bin",
        "NODE_PATH": "/path/to/node/lib/node_modules"
      }
    }
  }
}

Cursor IDE

For Cursor, install with:

npx mcprunner -- MYS

Troubleshooting

  • Connection Issues: Verify your MySQL credentials and ensure the MySQL server is running and accessible.
  • Permission Errors: Check that your MySQL user has the necessary permissions for the operations you're trying to perform.
  • Path Issues: If using Claude Desktop, ensure the PATH and NODE_PATH environment variables are correctly set.

For more detailed troubleshooting, check the console output when running the server.

Related MCPs

Milvus Vector Database
DatabasesPython

Connect to Milvus vector database for semantic search and vector operations

MotherDuck DuckDB
DatabasesPython

SQL analytics with DuckDB and MotherDuck for AI assistants

Alibaba Cloud Tablestore
DatabasesJava, Python

Connect to Alibaba Cloud Tablestore for vector search and RAG applications

About Model Context Protocol

Model Context Protocol (MCP) allows AI models to access external tools and services, extending their capabilities beyond their training data.

Generate Cursor Documentation

Save time on coding by generating custom documentation and prompts for Cursor IDE.