概要
What is MySQL MCP Server?
It provides a server to interact with MySQL databases using the Model Context Protocol (MCP). It is designed for accessing MySQL databases from WSL (Windows Subsystem for Linux) environments.
How to use MySQL MCP Server?
Clone the repository, create a Python 3.11+ virtual environment, install dependencies, and run the setup script. The server can be started directly (./run_direct.sh), as a module (./run_module.sh), or inside a Docker container (./run_docker.sh). Connection to MySQL is configured via environment variables (MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE).
Key features of MySQL MCP Server
- Retrieves a list of tables in the database
- Reads data from a specific table (up to 100 rows)
- Executes SQL queries (SELECT, SHOW TABLES, INSERT, UPDATE, DELETE)
- Implements MCP endpoints: list_resources, read_resource, list_tools, call_tool
- Supports direct, module, and Docker execution
- Provides Nox sessions for testing, formatting, and linting
Use cases of MySQL MCP Server
- Query a MySQL database from any MCP‑compatible client (e.g., AI assistants)
- Access a MySQL database running inside WSL from outside the subsystem
- Automate database interactions by calling SQL tools through the MCP protocol
- Run ad‑hoc SQL queries (SELECT, INSERT, UPDATE, DELETE) without a full client
FAQ from MySQL MCP Server
What is the maximum number of rows returned when reading a table?
The read_resource endpoint returns up to 100 rows from a table.
What environment variables are required to connect to MySQL?
MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASSWORD, and MYSQL_DATABASE must be set.
Can I run the server inside a Docker container?
Yes, build the Docker image with docker build -t mysql-mcp-server:latest . and run with ./run_docker.sh.
What Python version is needed?
Python 3.11 or higher is required.
How do I connect to a MySQL server running in WSL?
Configure the MySQL bind-address to 0.0.0.0, grant remote access to the user, and ensure the Windows firewall allows the MySQL port (default 13306).