home / mcp / mysql mcp server

MySQL MCP Server

An MCP server implementation that enables Claude AI to interact with MySQL databases.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "burakdirin-mysqldb-mcp-server": {
      "command": "uvx",
      "args": [
        "mysqldb-mcp-server"
      ],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_USER": "root",
        "MYSQL_DATABASE": "[optional]",
        "MYSQL_PASSWORD": "password",
        "MYSQL_READONLY": "true"
      }
    }
  }
}

This MCP server lets you connect to a MySQL database and run SQL queries through a standardized MCP interface. It abstracts database interactions behind two core tools, enabling you to connect to a database and execute arbitrary SQL safely from any MCP client.

How to use

You interact with this server through an MCP client by invoking its two available tools. Use the first to establish a connection to a specific MySQL database, and then use the second to run one or more SQL queries. The server will return confirmations for successful connections and JSON-formatted query results for your requests. You can chain multiple queries in a single request by separating them with semicolons.

How to install

Prerequisites: ensure Python and/or the Python package manager are available on your system. You may also use the MCP runtime tool available in your environment.

Install the MCP server package using your preferred tool:

uv pip install mysqldb-mcp-server

Alternatively, install directly with Python’s package manager:

pip install mysqldb-mcp-server

Additional configuration and usage notes

Environment variables configure how the server connects to your MySQL instance. Set these in your runtime environment before starting the server.

Required environment variables and their purposes:

  • - MYSQL_HOST: MySQL server address (default: localhost)
  • - MYSQL_USER: MySQL username (default: root)
  • - MYSQL_PASSWORD: MySQL password (default: empty)
  • - MYSQL_DATABASE: Initial database to connect to (optional)
  • - MYSQL_READONLY: Enable read-only mode (true/1 enables) (default: false)

Security and debugging tips

Run the server with the minimum necessary permissions and enable read-only mode if you only need data access without writes. For debugging, use the MCP Inspector to visualize runtime interactions and query flows.

Available tools

connect_database

Connects to a specific MySQL database with a given database name and returns a confirmation message on success.

execute_query

Executes SQL query or queries and returns results in JSON format; multiple queries can be sent separated by semicolons.