mysql-mcp-server
Enables running SQL queries (SELECT, INSERT, UPDATE, DELETE) against a MySQL database, with support for read-only or read-write mode, parameterized queries, and automatic reconnect.
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-server Show me the first 10 records 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-mcp-server
A Model Context Protocol (MCP) server that lets an MCP
client (Claude Desktop, Claude Code, etc.) run SQL against a MySQL database through four
tools: select, insert, update, and delete.
The server runs as a uv-managed Python package and communicates with the client over
stdio, as a subprocess started by the client.
Requirements
Python 3.11+
A reachable MySQL server
Related MCP server: Universal Database MCP Server
Installation
uv syncConfiguration
The server requires six values, each settable via environment variable and/or CLI flag (CLI flags take priority over environment variables):
Parameter | Env var | CLI flag | Required | Default |
Mode |
|
| yes | — ( |
Host |
|
| yes | — |
Port |
|
| no |
|
User |
|
| yes | — |
Password |
|
| yes | — |
Database |
|
| yes | — |
If a required value is missing, or MYSQL_MODE is not readonly/readwrite, the server
prints an error to stderr and exits with status code 1 without starting.
readonlymode: only theselecttool is allowed.insert/update/deleteare rejected with aPERMISSION_DENIEDerror.readwritemode: all four tools are allowed.
The mode is fixed for the lifetime of the process; it cannot be changed at runtime.
Security recommendation:
readonlymode is an application-level guard, not a substitute for database privileges. Where possible, pointreadonlymode at a MySQL account that only hasSELECTgrants.
Is a
.envfile required? No. The server itself never reads.envfiles — it only reads CLI flags and real process environment variables (os.environ). How you get values into that environment depends on how you run it:
As an MCP server (see Connecting from an MCP client below): the client (Claude Desktop/Code) spawns the server process and injects the
envblock from its own JSON config directly as environment variables. No.envfile is involved or needed.Running the CLI directly for local dev/testing:
.envis just a convenience so you don't have toexportsix variables by hand. Copy.env.exampleto.env, fill in real values, and load it explicitly — it is not read automatically:uv run --env-file .env mysql-mcp-server
.envis git-ignored and must never be committed.
Running
# Environment variables (or use `uv run --env-file .env mysql-mcp-server`, see above)
export MYSQL_MODE=readonly
export MYSQL_HOST=127.0.0.1
export MYSQL_PORT=3306
export MYSQL_USER=app_user
export MYSQL_PASSWORD=secret
export MYSQL_DATABASE=mydb
uv run mysql-mcp-server
# Or, equivalently, via CLI flags
uv run mysql-mcp-server \
--mysql-mode readonly \
--mysql-host 127.0.0.1 \
--mysql-port 3306 \
--mysql-user app_user \
--mysql-password secret \
--mysql-database mydbConnecting from an MCP client
Claude Desktop / Claude Code
Add an entry to your MCP client's server config (e.g. Claude Desktop's
claude_desktop_config.json, or .mcp.json for Claude Code):
{
"mcpServers": {
"mysql": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/mysql-mcp-server",
"run",
"mysql-mcp-server"
],
"env": {
"MYSQL_MODE": "readonly",
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "app_user",
"MYSQL_PASSWORD": "secret",
"MYSQL_DATABASE": "mydb"
}
}
}
}Restart the client after editing the config. The select, insert, update, and
delete tools (subject to MYSQL_MODE) should then be available to the model.
Tools
All four tools take {"query": string, "params"?: array} and always use %s
parameter-binding placeholders in query — never string-format user input into a query.
Tool | Allowed in | Query must start with | Success |
| any mode |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Every tool call returns one of:
{ "success": true, "data": { ... } }{ "success": false, "error": { "code": "...", "message": "..." } }Error codes: PERMISSION_DENIED, INVALID_QUERY_TYPE, MULTI_STATEMENT_NOT_ALLOWED,
DB_CONNECTION_ERROR, DB_EXECUTION_ERROR, INTERNAL_ERROR.
Multi-statement queries (;-separated) and any DDL/privilege statement (DROP,
TRUNCATE, ALTER, GRANT, CREATE USER, ...) are always rejected, since only the
four whitelisted statement types above are ever accepted.
Development
uv sync
uv run ruff format .
uv run ruff check .
uv run pytest -v
uv run uv build # packaging checkTroubleshooting
Server exits immediately with status 1: a required
MYSQL_*value is missing orMYSQL_MODEis invalid — check stderr for which one.DB_CONNECTION_ERROR: MySQL is unreachable, or the credentials are wrong. The server keeps running and will retry the connection on the next tool call.PERMISSION_DENIEDon insert/update/delete: the server is running inreadonlymode; restart it withMYSQL_MODE=readwriteif writes are intended.
Version history
0.1.0 — Initial release:
select/insert/update/deletetools,readonly/readwritemode policy, stdio MCP transport, automatic reconnect-and-retry on lost connections.
Available Tools
4 toolsdeleteA
Execute a DELETE statement and return the affected row count. Only available when the server is running in 'readwrite' mode; rejected with PERMISSION_DENIED in 'readonly' mode. A DELETE with no WHERE clause is executed but flagged with a warning, since it removes every row in the table. Always use %s placeholders in query with values passed via params; never concatenate user-supplied values into query.
Inputs: query (required), params. Returns: object
insertA
Execute an INSERT statement and return the affected row count and last insert id. Only available when the server is running in 'readwrite' mode; rejected with PERMISSION_DENIED in 'readonly' mode. Always use %s placeholders in query with values passed via params; never concatenate user-supplied values into query.
Inputs: query (required), params. Returns: object
selectA
Execute a read-only SELECT (or WITH ... SELECT) statement and return matching rows. Always available regardless of MYSQL_MODE. Always use %s placeholders in query with values passed via params; never concatenate user-supplied values into query.
Inputs: query (required), params. Returns: object
updateA
Execute an UPDATE statement and return the affected row count. Only available when the server is running in 'readwrite' mode; rejected with PERMISSION_DENIED in 'readonly' mode. An UPDATE with no WHERE clause is executed but flagged with a warning, since it affects every row in the table. Always use %s placeholders in query with values passed via params; never concatenate user-supplied values into query.
Inputs: query (required), params. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool maps to a distinct SQL operation (SELECT, INSERT, UPDATE, DELETE) with no functional overlap. Misselection is impossible because the actions are mutually exclusive.
All tool names are single lowercase verbs that directly match their SQL counterparts, forming a perfectly consistent and predictable pattern.
Four tools precisely cover the core CRUD operations for a database server without redundancy or excessive granularity, matching the expected scope.
The tool surface provides full coverage of data manipulation (create, read, update, delete) with no obvious gaps. Additional schema or transaction management is outside the stated read/write mode scope.
Maintenance
Related MCP Connectors
Read-only MCP server for ClassQuill, a tutoring-business-management platform.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Hosted SQL Server MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
An MCP server that provides read access to your cloud storage providers, bank accounts and more.
Related MCP Servers
- AlicenseAqualityBmaintenanceAn MCP server that provides read-only access to MySQL databases.4896 npm75MIT
- FlicenseNot gradedqualityDmaintenanceA versatile MCP server that connects to multiple relational databases (MySQL, PostgreSQL, Oracle, SQL Server, SQLite) and enables secure read-only SQL query execution and metadata access.4-
- AlicenseNot gradedqualityBmaintenanceA MySQL MCP server for local stdio clients, enabling database queries and management with read-only/write modes, audit logging, and configurable security.526 npmMIT
- FlicenseNot gradedqualityDmaintenanceA generic MCP server for MySQL operations, enabling listing databases/tables, describing schemas, running read-only SQL, and optionally executing write SQL with logging.1-