MySQL MCP Server
The MySQL MCP Server allows interaction with MySQL databases via JSON commands in a Docker container. You can:
Execute read-only SQL queries (
query)Test SQL write queries with automatic rollback (
test_execute)List all tables in the database (
list_tables)Describe the structure of a specific table (
describe_table)
Runs as a containerized service with special configurations for host connectivity, allowing MySQL database access from Docker environments with proper networking setup.
Uses environment variables stored in .env files for configuration management, particularly for sensitive database connection credentials.
Enables interaction with MySQL databases through read-only queries, schema exploration, and safe testing of write operations (with rollback). Provides tools for executing queries, listing tables, and describing table structures.
Implemented in TypeScript, providing type-safe database interactions with MySQL.
Click on "Install 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 Serverlist all tables in the database"
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 MCP Server
An MCP server for interacting with MySQL databases.
This server supports executing read-only queries (query) and write queries that are ultimately rolled back (test_execute).
Setup
Environment Variables
Add the following environment variables to ~/.mcp/.env:
MYSQL_HOST=host.docker.internal # Hostname to access host services from Docker container
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your_passwordNote:
host.docker.internalis a special DNS name for accessing host machine services from Docker containers. Use this setting when connecting to a MySQL server running on your host machine. If connecting to a different MySQL server, change to the appropriate hostname.
mcp.json Configuration
{
"mcpServers": {
"mysql": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--add-host=host.docker.internal:host-gateway",
"--env-file",
"/Users/username/.mcp/.env",
"ghcr.io/xiangma9712/mcp/mysql"
]
}
}
}Related MCP server: MCP MySQL Server
Usage
Starting the Server
docker run -i --rm --add-host=host.docker.internal:host-gateway --env-file ~/.mcp/.env ghcr.io/xiangma9712/mcp/mysqlNote: If you're using OrbStack,
host.docker.internalis automatically supported, so the--add-hostoption can be omitted. While Docker Desktop also typically supports this automatically, adding the--add-hostoption is recommended for better reliability.
Available Commands
1. Execute Read-only Query
{
"type": "query",
"payload": {
"sql": "SELECT * FROM your_table"
}
}Response:
{
"success": true,
"data": [
{
"id": 1,
"name": "example"
}
]
}2. Test Query Execution
{
"type": "test_execute",
"payload": {
"sql": "UPDATE your_table SET name = 'updated' WHERE id = 1"
}
}Response:
{
"success": true,
"data": "The UPDATE SQL query can be executed."
}3. List Tables
{
"type": "list_tables"
}Response:
{
"success": true,
"data": ["table1", "table2", "table3"]
}4. Describe Table
{
"type": "describe_table",
"payload": {
"table": "your_table"
}
}Response:
{
"success": true,
"data": [
{
"Field": "id",
"Type": "int(11)",
"Null": "NO",
"Key": "PRI",
"Default": null,
"Extra": ""
},
{
"Field": "name",
"Type": "varchar(255)",
"Null": "YES",
"Key": "",
"Default": null,
"Extra": ""
}
]
}Implementation Details
Implemented in TypeScript
Uses mysql2 package
Runs as a Docker container
Accepts JSON commands through standard input
Returns JSON responses through standard output
Uses
host.docker.internalto connect to host MySQL (compatible with both OrbStack and Docker Desktop)
Security Considerations
Uses environment variables for sensitive information management
SQL injection prevention is the implementer's responsibility
Proper network configuration required for production use
Appropriate firewall settings needed when connecting to host machine services
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Flicense-qualityDmaintenanceEnables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.Last updated
- Alicense-qualityDmaintenanceEnables interaction with MySQL databases through MCP, supporting query execution, table operations (insert, update, delete), and schema inspection for natural language database management.Last updated71MIT
- Alicense-qualityDmaintenanceEnables AI models to interact with MySQL databases through standardized operations including querying, executing commands, listing tables, and describing table structures with secure prepared statement support.Last updated679MIT
- FlicenseAqualityCmaintenanceEnables querying local MySQL databases and managing Docker containers (listing, logs) through natural language via the Model Context Protocol.Last updated494
Related MCP Connectors
Connect to PlanetScale databases, branches, schema, query insights, and execute SQL
GibsonAI MCP server: manage your databases with natural language
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/xiangma9712/mysql-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server