home / mcp / mysql mcp server

MySQL MCP Server

A Model Context Protocol server that provides read-only access to MySQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.

Installation
Add the following to your MCP client configuration file.

Configuration

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

I provide a Model Context Protocol server that lets you inspect MySQL schemas and run read-only queries. It’s designed for large language models to safely explore database structures and data without risking modification.

How to use

You run the MCP server locally and connect your MCP client to it. The server exposes a read-only toolset that queries MySQL and returns table schemas so your models can understand database structures. Use the mysql_query tool to execute safe, read-only SQL within a READ ONLY transaction. You can point the server at a specific database with the MYSQL_DB environment variable to focus on one database, or leave it blank to retrieve schemas across all databases.

How to install

Prerequisites: make sure you have Node.js installed (including npm). You also need access to a MySQL database you can connect to.

Install and run the MCP server using the standard runtime tool. The server is intended to be launched with npx, passing the MCP package name and the appropriate environment variables.

Example steps you can follow:

# 1) Ensure Node.js and npm are installed
node -v
npm -v

# 2) Run the MCP server for MySQL using npx with environment overrides
MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_USER=root MYSQL_PASS="" MYSQL_DB=db_name \
  npx -y @benborla29/mcp-server-mysql

# 3) If you are integrating with a client like Claude Desktop, include the MCP config in your client setup (see the configuration section for details)

Additional content

Configuration and troubleshooting details are provided to help you run smoothly in local and client environments. The server discovers MySQL table schemas automatically from database metadata and exposes a read-only interface for querying.

If you need to connect through Claude Desktop or another MCP client, you can configure the client to start the MCP server with the exact command and environment variables shown in the example configuration below.

Available tools

mysql_query

Execute read-only SQL queries against the connected database. All queries run within a READ ONLY transaction.