MySQL MCP Server
Provides tools to interact with MySQL databases, including listing databases and tables, describing table schemas, and executing read-only SQL queries (with optional write support when configured).
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 list tables in mydb"
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 (FastMCP)
Python MCP server built with FastMCP to connect to MySQL. It exposes tools to list databases and tables, describe tables, and execute SQL queries (read-only by default).
Requirements
Python 3.10+
MySQL reachable (host, username, password)
Related MCP server: @cano721/mysql-mcp-server
Installation
Requires uv. In the project directory:
cd /Users/macbook/projets/MCP/mysql
uv syncThis creates the virtual environment (.venv) and installs dependencies.
No pip step is required.
To validate locally:
uv run env PYTHONPATH=src python -m mysql_mcpConfiguration
How the server reads credentials
The server uses environment variables with prefix MYSQL_. The resolution happens in two layers:
First: values provided to the process via
envin Cursormcp.json(or via shell/CI).Second (fallback): values from the project
.envfile, but only for fields that are not defined in the environment.
This means that if you configure MYSQL_USER and MYSQL_PASSWORD in mcp.json, the project .env file will not override those values.
Environment variables (or .env file):
Variable | Required | Description | Default |
| Yes | MySQL username | - |
| Yes | Password | - |
| No | Host | 127.0.0.1 |
| No | Port | 3306 |
| No | Default database | - |
| No | Connection pool size | 5 |
| No | Allow INSERT/UPDATE/DELETE | false |
| No | Enable TLS/SSL for MySQL connection | false |
| No | Validate server certificate chain | true |
| No | Path to CA bundle (recommended in prod) | - |
| No | Client certificate path (for mTLS) | - |
| No | Client private key path (for mTLS) | - |
Security details
By default, the server only accepts read-only queries (for example: SELECT, SHOW, DESCRIBE).
When MYSQL_ALLOW_WRITE=true, it also accepts INSERT, UPDATE, DELETE, and REPLACE.
Additional rules:
UPDATEandDELETErequire an explicitWHEREclause (otherwise the query is rejected).
.env file (optional)
If you want, create /Users/macbook/projets/MCP/mysql/.env using the same format as the variables above.
You can use /.env.example in this repository as a reference.
Minimum example (read-only):
MYSQL_USER=user
MYSQL_PASSWORD=password
MYSQL_DATABASE=database
MYSQL_ALLOW_WRITE=falseProduction note (require_secure_transport=ON)
If your MySQL server enforces secure transport (--require_secure_transport=ON),
you must enable TLS:
MYSQL_SSL_ENABLED=true
MYSQL_SSL_VERIFY_CERT=true
MYSQL_SSL_CA=/absolute/path/to/ca.pemIf you do not have a CA certificate available yet, you can still use TLS encryption without certificate validation:
MYSQL_SSL_ENABLED=true
MYSQL_SSL_VERIFY_CERT=falseThis is useful as a temporary fallback, but it is less secure (susceptible to
man-in-the-middle attacks). Prefer MYSQL_SSL_VERIFY_CERT=true with a valid CA
bundle in production.
If your database requires mTLS, also set:
MYSQL_SSL_CERT=/absolute/path/to/client-cert.pem
MYSQL_SSL_KEY=/absolute/path/to/client-key.pemCursor note (mcp.json)
If you are using Cursor, the most common setup is to configure MYSQL_* directly in the env of the mysql server block inside /Users/macbook/.cursor/mcp.json (as shown in the Cursor example below).
This avoids relying on the local .env file for credentials.
Running the server
STDIO (e.g. Claude Desktop, Cursor):
/usr/bin/env PYTHONPATH=/Users/macbook/projets/MCP/mysql/src /Users/macbook/projets/MCP/mysql/.venv/bin/python -m mysql_mcpAlternative:
uv run env PYTHONPATH=src python -m mysql_mcpHTTP (port 8000):
/Users/macbook/projets/MCP/mysql/.venv/bin/python -c "from mysql_mcp.server import run; run(transport='http', port=8000)"Or with the FastMCP CLI:
uv run fastmcp run mysql_mcp.server:mcp --transport http --port 8000MCP Tools
list_databases - Lists all databases.
list_tables - Lists tables in a database (optional
databaseparameter).describe_table - Returns column information (name, type, null, key, default, extra) for a table.
execute_query - Executes a validated SQL query (following the security rules).
Cursor configuration example
In Cursor Settings > MCP, add a server that will be started via stdio.
Important: for stdio, do not set transport=http and do not provide port. The server uses stdio by default.
Example (JSON in ~/.cursor/mcp.json)
If you use Cursor global configuration, edit /Users/macbook/.cursor/mcp.json (or create a .cursor/mcp.json inside this project directory) and add a mcpServers entry like this:
{
"mcpServers": {
"mysql": {
"command": "/usr/bin/env",
"args": [
"PYTHONPATH=/Users/macbook/projets/MCP/mysql/src",
"/Users/macbook/projets/MCP/mysql/.venv/bin/python",
"-m",
"mysql_mcp"
],
"cwd": "/Users/macbook/projets/MCP/mysql",
"env": {
"MYSQL_USER": "user",
"MYSQL_PASSWORD": "password",
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_DATABASE": "database",
"MYSQL_ALLOW_WRITE": "false"
}
}
}
}Per-project (recommended) - 3 environments
You can configure multiple MySQL targets per workspace by creating/updating:
/Users/macbook/projets/MCP/mysql/.cursor/mcp.json
Example (3 server blocks, read-only by default):
{
"mcpServers": {
"mysql_local": {
"command": "/usr/bin/env",
"args": [
"PYTHONPATH=/Users/macbook/projets/MCP/mysql/src",
"/Users/macbook/projets/MCP/mysql/.venv/bin/python",
"-m",
"mysql_mcp"
],
"cwd": "/Users/macbook/projets/MCP/mysql",
"env": {
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_DATABASE": "database",
"MYSQL_ALLOW_WRITE": "false"
}
},
"mysql_staging": {
"command": "/usr/bin/env",
"args": [
"PYTHONPATH=/Users/macbook/projets/MCP/mysql/src",
"/Users/macbook/projets/MCP/mysql/.venv/bin/python",
"-m",
"mysql_mcp"
],
"cwd": "/Users/macbook/projets/MCP/mysql",
"env": {
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_HOST": "staging-db.example.com",
"MYSQL_PORT": "3306",
"MYSQL_DATABASE": "database",
"MYSQL_ALLOW_WRITE": "false"
}
},
"mysql_prod": {
"command": "/usr/bin/env",
"args": [
"PYTHONPATH=/Users/macbook/projets/MCP/mysql/src",
"/Users/macbook/projets/MCP/mysql/.venv/bin/python",
"-m",
"mysql_mcp"
],
"cwd": "/Users/macbook/projets/MCP/mysql",
"env": {
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_HOST": "prod-db.example.com",
"MYSQL_PORT": "3306",
"MYSQL_DATABASE": "database",
"MYSQL_ALLOW_WRITE": "false",
"MYSQL_SSL_ENABLED": "true",
"MYSQL_SSL_VERIFY_CERT": "true",
"MYSQL_SSL_CA": "/absolute/path/to/ca.pem"
}
}
}
}Notes:
For
stdio, do not settransport=httpand do not provideport.If you removed the project
.env, it is still fine:MYSQL_*must be provided viaenvinmcp.json(as shown above).Recommended startup in MCP clients is setting
PYTHONPATHdirectly incommand/args(via/usr/bin/env), because some clients do not consistently applyenv.PYTHONPATH.
Option A (recommended) - using uv:
Command:
uvArgs:
run,env,PYTHONPATH=src,python,-m,mysql_mcpCwd: project directory (where
pyproject.tomllives)Env: set
MYSQL_USER,MYSQL_PASSWORD, and optionallyMYSQL_HOST,MYSQL_PORT,MYSQL_DATABASE,MYSQL_ALLOW_WRITE,MYSQL_SSL_*
Option B - using the Makefile shortcut:
Command:
makeArgs:
upCwd: project directory
Env: same values as Option A
Alternative - using the venv interpreter directly:
Command:
/usr/bin/envArgs:
PYTHONPATH=/absolute/path/to/project/src,.venv/bin/python,-m,mysql_mcp
License
MIT.
Available Tools
4 toolsdescribe_tableA
Return column information (name, type, null, key, default, extra) for a table.
Inputs: table (required), database. Returns: result
execute_queryA
Execute a read-only SQL query (SELECT, SHOW, DESCRIBE, etc.). Write operations require MYSQL_ALLOW_WRITE=true and must include a proper WHERE clause for UPDATE/DELETE.
Inputs: query (required), database. Returns: result
list_databasesA
List all databases on the MySQL server.
Inputs: no named parameters. Returns: result
list_tablesA
List tables in a database. If database is empty, uses the default configured database.
Inputs: database. Returns: result
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 targets a distinct resource operation: databases, tables, schema, and custom queries. There is no ambiguity because the specific tools are convenient shortcuts, and execute_query is the catch-all for arbitrary read-only SQL.
All tool names follow the verb_noun pattern with lowercase and underscores: list_databases, list_tables, describe_table, execute_query. The convention is consistent and predictable.
Four tools is well-scoped for a read-only MySQL server. Each tool earns its place: listing databases, listing tables, describing schemas, and running custom queries—no superfluous tools.
Covers the full read-only workflow: discover databases, list tables, inspect column structure, and execute arbitrary SELECT/SHOW queries. Missing write operations are intentional, but there is no tool for viewing indexes/foreign keys, which is a minor gap.
Maintenance
Related MCP Connectors
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.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Query your own databases and Data Sets with read-only SQL, and build hosted dashboards.
Hosted MySQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA server that provides LLMs with read-only access to MySQL databases, allowing them to inspect database schemas and execute read-only queries.136 npm16MIT
- AlicenseAqualityDmaintenanceEnables read-only MySQL database access, allowing listing databases, tables, describing schemas, and executing SELECT/SHOW/DESCRIBE/EXPLAIN queries.730 npm4MIT
- FlicenseAqualityDmaintenanceProvides read-only access to a local MySQL database, enabling SQL queries, database and table listings, and table schema descriptions.4-
- 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-