mysql-mcp-server
Provides a mysql_query tool for executing SQL queries against a MySQL database, with support for parameterized queries, configurable write and DDL operations, and result row limits.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mysql-mcp-servershow me the first 10 rows from the customers table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MySQL Model Context Protocol (MCP) Server
A high-performance, lightweight Model Context Protocol (MCP) Server built with Bun and TypeScript. It provides a secure mysql_query tool allowing AI assistants (such as Claude, Cursor, VS Code Copilot, and custom MCP clients) to execute SQL queries against a MySQL database.
Features
⚡ Built on Bun: Fast startup and lightweight footprint.
🔌 Streamable HTTP Transport: Implements standard MCP HTTP/SSE transport (
/mcp).🛡️ Safe by Default: Read-only query execution by default. Write (
INSERT,UPDATE,DELETE) and DDL (CREATE,ALTER,DROP) operations require explicit configuration.🔒 File-Based Secrets (
_FILE): Supports reading credentials from mounted files (MYSQL_USER_FILE,MYSQL_PASSWORD_FILE).⚡ Connection Pooling: Uses
mysql2with automatic connection management.
Related MCP server: MySQL ReadOnly MCP Server
Quick Start
Basic docker run
Run the container by passing your MySQL database credentials:
docker run -d \
--name mysql-mcp-server \
-p 127.0.0.1:3000:3000 \
-e MYSQL_HOST=your-mysql-host.example.com \
-e MYSQL_PORT=3306 \
-e MYSQL_DATABASE=my_database \
-e MYSQL_USER=my_user \
-e MYSQL_PASSWORD=my_password \
liorcodev/mysql-mcp-server:latestThe MCP HTTP endpoint will be available at:
http://localhost:3000/mcp
Connecting to MySQL on localhost / Host Machine
If your MySQL database runs directly on your host machine (outside Docker), standard localhost or 127.0.0.1 refers to the container itself. Use host.docker.internal instead:
docker run -d \
--name mysql-mcp-server \
-p 127.0.0.1:3000:3000 \
-e MYSQL_HOST=host.docker.internal \
-e MYSQL_DATABASE=my_database \
-e MYSQL_USER=my_user \
-e MYSQL_PASSWORD=my_password \
liorcodev/mysql-mcp-server:latestEnvironment Variables
Variable | Required | Default | Description |
| Yes | — | MySQL server hostname or IP address |
| No |
| MySQL server port |
| Yes | — | Target database name |
| Yes* | — | MySQL username |
| Yes* | — | Path to file containing MySQL username (overrides |
| No | — | MySQL password |
| No | — | Path to file containing MySQL password (overrides |
| No |
| Maximum connections in the pool |
| No |
| Set to |
| No |
| Set to |
| No |
| Container IP interface to bind to (leave as |
| No |
| Internal container port for HTTP server binding |
* Either MYSQL_USER or MYSQL_USER_FILE must be provided.
Reading Credentials from Files (_FILE Environment Variables)
To avoid passing raw credentials as plain-text environment variables, store your credentials in files, mount them into the container using volume mounts (-v), and reference their paths using MYSQL_USER_FILE and MYSQL_PASSWORD_FILE:
docker run -d \
--name mysql-mcp-server \
-p 127.0.0.1:3000:3000 \
-v /path/to/secrets/user.txt:/run/secrets/mysql_user:ro \
-v /path/to/secrets/password.txt:/run/secrets/mysql_password:ro \
-e MYSQL_HOST=your-mysql-host.example.com \
-e MYSQL_DATABASE=my_database \
-e MYSQL_USER_FILE=/run/secrets/mysql_user \
-e MYSQL_PASSWORD_FILE=/run/secrets/mysql_password \
liorcodev/mysql-mcp-server:latest(Binding to 127.0.0.1 keeps the port off your LAN/public interfaces — only processes on the host machine can reach it.)
(Note: Native Docker Secrets --secret are supported by Docker Swarm and Docker Compose. For standalone docker run, volume mounting local files into /run/secrets/ achieves the exact same security benefit for file-based secret reading).
Docker Compose
For repeatable local/production deployments, use the included docker-compose.yml (plain env vars) or docker-compose-secret.yml (file-based secrets via Docker's secrets: block, reading from ./secrets/mysql_user.txt and ./secrets/mysql_password.txt — see secrets/README.md):
# plain env vars (edit docker-compose.yml directly, or add MYSQL_USER/MYSQL_PASSWORD)
docker compose -f docker-compose.yml up -d --build
# file-based secrets
docker compose -f docker-compose-secret.yml up -d --buildBoth compose files build the image locally from the repo's Dockerfile and publish it on 127.0.0.1:3000 only.
Local Development
Requires Bun.
bun install
cp .env.example .env # fill in MYSQL_HOST / MYSQL_DATABASE / MYSQL_USER / MYSQL_PASSWORD etc.
bun run dev # watch mode, http://localhost:3000/mcp
bun run start # no watchMCP Tool Documentation
mysql_query
Executes a SQL statement against the configured MySQL database.
Parameters:
sql(string, required): SQL query to execute. Use?placeholders for parameterized queries.params(array, optional): Array of parameter values substituted into?placeholders.maxRows(number, optional): Max rows returned forSELECTqueries (default:500, hard cap:5000).
Safety & Permissions:
By default, only read queries (
SELECT,SHOW,EXPLAIN, etc.) are permitted.Set
MYSQL_ALLOW_WRITE_OPERATIONS=trueto enable write operations.Set
MYSQL_ALLOW_DDL_OPERATIONS=trueto enable schema modifications.
MCP Client Configuration Example
To connect an MCP client using Streamable HTTP transport:
{
"mcpServers": {
"mysql": {
"url": "http://localhost:3000/mcp"
}
}
}This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
- dataOAuthco.thinair
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Draxlr's remote MCP server connects AI assistants to your SQL databases and dashboards. Explore schemas, run read-only queries, manage saved queries and dashboards, and export results, all with row-level security so each user sees only their own data.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely query MySQL databases with read-only access by default, supporting table listing, structure inspection, and SQL queries with optional write operation control.10 npmMIT
- AlicenseAqualityDmaintenanceEnables AI assistants to safely query MySQL databases with read-only access, featuring SQL injection protection, connection pooling, and automatic query limits for secure database exploration.427 npmMIT
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol service that enables AI assistants to directly query and manage MySQL databases through natural language. It supports SQL execution, schema inspection, and atomic transactions for comprehensive database interaction.-
- AlicenseAqualityDmaintenanceEnables AI agents to safely interact with MySQL/MariaDB databases, supporting read-only queries by default with optional write operations and access control.8MIT