
mcp-mysql
io.github.ranjian/mcp-mysql
Read-only MySQL MCP server with multi-connection profiles and safe SELECT queries.
Documentation
mcp-mysql
A small, dependency-light Model Context Protocol server that gives MCP clients (Trae, Cursor, Claude Desktop, ...) read-only access to one or more MySQL databases through a single db_profiles.json file.
- Multiple connections in one server (production / test / reporting ...), each with its own credentials
- Per-database notes and usage rules returned to the model before it writes SQL
- Two tools only:
list_connectionsandexecute_sql - Any SQL client can be used, but the server is designed for read-only accounts
Install
pipx install jj-mcp-mysql
# or
pip install jj-mcp-mysql
The distribution is named jj-mcp-mysql; the installed command is mcp-mysql.
Configure
Copy the sample profile file and fill in your connections:
cp db_profiles.sample db_profiles.json
{
"default_connection": "my_conn",
"connections": {
"my_conn": {
"description": "Test database",
"usage": "Read-only account. Only SELECT is allowed.",
"host": "127.0.0.1",
"port": 3306,
"user": "readonly",
"password": "change-me",
"charset": "utf8mb4",
"databases": ["your_database"],
"default_database": "your_database"
}
}
}
Keys starting with _ are treated as samples and are skipped.
Run
export MCP_DB_PROFILES_FILE=/absolute/path/to/db_profiles.json
mcp-mysql
If MCP_DB_PROFILES_FILE is not set, the server looks for db_profiles.json in the current working directory.
MCP client configuration
{
"mcpServers": {
"mcp-mysql": {
"command": "mcp-mysql",
"env": {
"MCP_DB_PROFILES_FILE": "/absolute/path/to/db_profiles.json"
}
}
}
}
Tools
| Tool | Purpose |
|---|---|
list_connections | List connections, their usage notes and available databases |
execute_sql | Run SQL on a chosen connection and database; omit connection / database to use the defaults |
The server injects usage notes into the MCP instructions, so the model knows which connection and database to pick. SELECT statements are expected to carry an explicit LIMIT (100 rows by default in prompts).
Security notes
- Use a read-only MySQL account; the server does not block writes on its own.
db_profiles.jsoncontains credentials and is git-ignored. Never commit it.- Prefer environment variables or a file outside the repository for production credentials.
Development
python -m venv .venv
.venv/Scripts/pip install -e .
python -m mcp_mysql
Release
python -m build
twine upload dist/*
mcp-publisher validate
mcp-publisher publish
mcp-publisher publishes server.json to the official MCP Registry. Update name, repository and version fields before publishing.
jj-mcp-mysqlpip install jj-mcp-mysql