home / mcp / mysql mcp server

MySQL MCP Server

An MCP server implementation that integrates with MySQL databases, providing secure database access capabilities for LLMs.

Installation
Add the following to your MCP client configuration file.

Configuration

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

You have a MySQL MCP Server that lets you securely query and modify a MySQL database through an MCP-enabled client. It supports read-only queries, write operations with transaction safety, and built-in security and monitoring to help LLMs interact with your data safely and efficiently.

How to use

Use this MCP server with any MCP client to perform database operations from your language models. You can run read-only queries to fetch data, list tables, and inspect table structures. For changes, you can execute INSERT, UPDATE, and DELETE statements with automatic transaction handling. All inputs can be parameterized to protect against SQL injection, and results include affected rows and insert IDs. Security features include read-only transaction mode for SELECTs, query length and result size limits, and logging for performance monitoring.

Typical usage patterns include asking your LLM to:

How to install

Prerequisites you need before installing this MCP server:

  • Node.js 18+
  • MySQL Server
  • An MCP-compatible LLM service

Install the MCP server package globally using the following command:

npm install -g @kevinwatt/mysql-mcp

Configuration and runtime notes

When running the MCP server, you set connection details via environment variables. The following variables are used to connect to your MySQL database:

  • MYSQL_HOST
  • MYSQL_PORT
  • MYSQL_USER
  • MYSQL_PASS
  • MYSQL_DB

A ready-to-use runtime example shows how to start the MCP server locally with the required environment variables set.

Manual start

If you prefer to start the MCP server manually without a client, run the following command. The environment variables should be set in your shell or via a start script.

npx @kevinwatt/mysql-mcp

Available tools

mysql_query

Execute read-only SELECT queries with inputs and limits for query length and result size.

mysql_execute

Execute data modification statements (INSERT/UPDATE/DELETE) with parameter support and automatic transaction handling.

list_tables

List all tables in the current database without inputs.

describe_table

Show the structure of a specified table.