
MySQL MCP Server
Secure, structured access to MySQL databases for AI clients — query, sample, and inspect schemas via MCP.
Add to your client
Copy the config for your MCP client and paste it into its config file.
pip install mysql-mcp-serverPaste into ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"mysql-mcp-server": {
"command": "uv",
"args": [
"--directory",
"path/to/mysql_mcp_server",
"run",
"mysql_mcp_server"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}Step-by-step guides: Add to Claude Desktop · Add to Cursor · Add to Windsurf
Before you start
- Python with pip (or uv/uvx) to install and run the server
- A running MySQL database with reachable host/port
- MySQL credentials supplied via MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD (and optionally MYSQL_DATABASE) environment variables
- uv installed when using the uv/uvx-based config
About MySQL MCP Server
MySQL MCP Server bridges AI applications and MySQL databases through the Model Context Protocol, making database exploration and analysis safer and more structured. It exposes tables as MCP resources, supports executing standard SQL (SELECT, SHOW, DESCRIBE, and DML), schema introspection, and data sampling. It runs over STDIO or Streamable HTTP (SSE), supports an optional multi-database mode (omit MYSQL_DATABASE to query across databases with database.table notation), SSH tunneling, and SSL/TLS. Connection settings are supplied via MYSQL_* environment variables, and a .env file is auto-loaded via python-dotenv for local runs. Available via PyPI, Smithery, the Claude Code CLI, and a hosted option (Fronteir AI).
Tools & capabilities (3)
execute_sqlExecutes any standard SQL query. Argument: query (string). Supports SELECT, SHOW, DESCRIBE, and DML (INSERT, UPDATE, DELETE); DML operations are marked with a destructive hint. Single statements only — multi-statement queries are not supported. Use database.table notation to query any database regardless of the MYSQL_DATABASE setting.
get_schema_infoProvides detailed metadata about database structures. Argument: table_name (optional string). Outputs column names, types, nullability, default values, and comments. Pass database.table for cross-database lookups; bare names use the configured database. Identifiers must contain only alphanumeric characters, underscores, and $ (a dot is allowed as a database/table separator).
get_table_sampleFetches a representative sample of data. Arguments: table_name (string), limit (optional integer, max 20). Useful for quickly understanding data formats and content without fetching large result sets. Pass database.table for cross-database sampling; bare names use the configured database. Same identifier validation rules as get_schema_info.
What this server can do
MySQL MCP Server provides tools for these capabilities — tap one to see every MCP server that does the same:
When to use it
- Explore an unfamiliar MySQL database — discover tables, inspect schemas, and sample data via the explore_database prompt
- Deep-dive into a specific table's schema and sample data with the analyze_table prompt
- Run ad-hoc SQL queries (SELECT/SHOW/DESCRIBE and DML) from an AI client with structured error handling
- Query across multiple databases using database.table notation in multi-database mode
- Securely connect to remote MySQL instances over SSL/TLS or SSH tunnels for analysis and reporting
Security notes
Requires database access to function. Table/database identifiers passed to get_schema_info and get_table_sample are validated against a strict whitelist (alphanumeric, underscore, and $; a single dot allowed as database.table separator) to prevent SQL injection. Supports SSL/TLS and SSH tunneling for encrypted remote connections. Passwords and SSH private keys are masked in logs. Use a dedicated MySQL user with minimal permissions; never use root or administrative credentials. See SECURITY.md for hardening guidance.
MySQL MCP Server FAQ
Which transports are supported?
Both standard input/output (STDIO) and Streamable HTTP (SSE). SSE mode (MCP_TRANSPORT=sse) is recommended for remote/self-hosted deployments.
Why do I see 'Missing required database configuration' in Claude Desktop/Code?
Those hosts launch the server from their own working directory, so a project .env file is not found. Put your MYSQL_* values in the env block of the MCP config instead of relying on .env.
Can I query more than one database?
Yes. Omit MYSQL_DATABASE to enable multi-database mode; list_resources then returns all user databases and you use fully qualified database.table names in queries. Only single SQL statements are supported.
Can I run it directly from the command line with Python?
No. It is designed to be integrated with AI applications like Claude Desktop and should not be run standalone. For debugging you can use the MCP Inspector.
Alternatives to MySQL MCP Server
Compare all alternatives →Google's official MCP server with prebuilt BigQuery tools, querying datasets via Application Default Credentials.
Read/write Postgres access plus index tuning, EXPLAIN plans, and database health analysis for AI agents.
Official Supabase server: manage tables, run SQL, branches, configs and edge functions from your AI client.
Compare MySQL MCP Server with: