Get the FREE Ultimate OpenClaw Setup Guide →

mcp-mysql

A lightweight MCP server for MySQL, built with python

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio alexcc4-mcp-mysql-server uvx run main.py \
  --env DB_HOST="Database host" \
  --env DB_NAME="Database name" \
  --env DB_PORT="Database port (defaults to 3306 if not specified)" \
  --env DB_USER="Database username" \
  --env DB_PASSWORD="Database password"

How to use

This MCP server provides a lightweight interface to a MySQL database, exposing read-only access to database schema and data through the MCP protocol. You can list all tables, fetch detailed schema information for tables, and execute read-only SQL queries via the server's tools. The available resources include mysql://schema for the complete database structure and mysql://tables for a list of all tables. The primary tool exposed by the server is query_data, which executes read-only SQL queries and returns the results. Use these capabilities to inspect schemas, preview data, and run safe queries without granting full database access. When integrating with Claude or other assistants, configure the server in your client’s MCP setup and provide the required environment variables to connect to your MySQL instance.

How to install

Prerequisites:

  • Python 3.12.2+ (or a compatible Python environment)
  • uv (uvx) for running Python MCP servers
  • Access to a MySQL server with appropriate credentials

Installation steps:

  1. Clone the repository: git clone git@github.com:alexcc4/mcp-mysql-server.git cd mysql-mcp-server

  2. Install dependencies using uv (recommended): uv sync

  3. Ensure your environment is configured with the required variables before starting the server. Example variables are shown in the Configuration section of the README. You can set them in your shell or in your Claude Desktop configuration as needed.

Additional notes

Tips and considerations:

  • Use a least-privilege MySQL user with only read permissions to the target database.
  • Avoid exposing root credentials; prefer dedicated read-only accounts.
  • If you plan to run multiple databases, consider separate environment configurations for isolation.
  • When deploying with Claude Desktop, ensure the config file maps the environment variables correctly to the server environment.
  • If you encounter connection issues, verify network access to the DB host and confirm that DB_PORT is correct (default is 3306).
  • For security, consider adding a query whitelist in your production environment to restrict what read-only queries can run.

Related MCP Servers

Sponsor this space

Reach thousands of developers