A Model Context Protocol server that provides secure, read-only access to MySQL databases for AI assistants
Configuration
View docs{
"mcpServers": {
"guido-marinho-mcp-mysql": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"guidomarinho/mcp-mysql:latest",
"mysql://root:[email protected]:3306/you_db"
]
}
}
}You can access MySQL data sources through a Model Context Protocol (MCP) server that exposes read-only SQL query capabilities. This server lets you run safe, read-only queries against your MySQL databases and discover table schemas, all through MCP clients.
To connect to your MySQL database through MCP, run a server instance that exposes a read-only query endpoint. You can interact with the server using an MCP client to perform read-only SQL operations such as SELECT, SHOW, DESCRIBE, and EXPLAIN. The server ensures all queries execute within READ ONLY transactions for safety. You can also inspect automatic table schemas, including column names, data types, keys, and constraints, to understand the data model before querying.
Key usage patterns you can apply include: - Run read-only queries to fetch data for dashboards or reports. - Explore table schemas to map your data sources to MCP models. - Use schema discovery to understand available columns and relationships without altering the database.
Prerequisites:
- Node.js and npm (for local tooling and builds)
- Docker (optional, for containerized usage)
- Access to your MySQL server (host, port, database, user, password)Install the MCP MySQL server tooling using one of the supported approaches. The server can be run via Docker, or through npm/npx for quick local usage.
Install via Docker (recommended for quick experimentation):
# Pull the MCP MySQL server image
docker pull guidomarinho/mcp-mysql
# Run the server pointing to your MySQL instance
# Replace the URL with your actual connection string
# Example: mysql://root:password@host:3306/database
docker run -i --rm guidomarinho/mcp-mysql mysql://root:password@host:3306/databaseInstall via npm for development or local usage:
npm install -g @modelcontextprotocol/server-mysqlRun with npx for quick testing without global install:
npx -y @modelcontextprotocol/server-mysql mysql://user:password@localhost:3306/databaseExample of integrating the server in MCP configuration using stdio mode (Docker-based) with an explicit MCP entry:
{
"mcpServers": {
"mysql_mcp": {
"type": "stdio",
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"guidomarinho/mcp-mysql:latest",
"mysql://root:[email protected]:3306/you_db"
],
"env": []
}
}
}You can also run the server using a local Docker command variant that targets your host MySQL instance, as shown in an MCP JSON example:
{
"mcpServers": {
"mysql": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/mysql",
"mysql://root:[email protected]:3306/database"
]
}
}
}If you prefer using NPX for a quick local run without installing a binary, you can configure as shown here:
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-mysql",
"mysql://user:password@localhost:3306/database"
]
}
}
}Connection string format you will use to point the MCP server to your database is: mysql://username:password@host:port/database.
Note: When using Docker to connect to a MySQL server on your host machine, use host.docker.internal instead of localhost.
Available tool: query — Execute read-only SQL queries (SELECT, SHOW, DESCRIBE, EXPLAIN). All queries run within READ ONLY transactions.
Resource discovery: Table schemas are automatically discovered, exposing tables, columns, types, keys, and constraints for you to understand the data model.
Execute read-only SQL queries (SELECT, SHOW, DESCRIBE, EXPLAIN) with all queries running in READ ONLY transactions.
Automatically discover table schemas including tables, columns, types, keys, and constraints for your MySQL sources.