MySQL MCP Server

by koh-yoshimoto

Not rated
GitHub

About

An MCP server for accessing and managing MySQL databases.

Details

Author
koh-yoshimoto
Categories
Database, Other

Setup

Install MySQL MCP Server in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/koh-yoshimoto/mysql-mcp-server

Follow the installation instructions in the repository README, then restart your MCP client.

A Model Context Protocol (MCP) server that provides MySQL database access through standardized tools.

- Query Execution: Execute arbitrary SQL queries
- Schema Inspection: View table schemas
- Table Listing: List all tables in the database
- Query Analysis: Analyze query execution plans with optimization suggestions

- Go 1.21+ (developed with Go 1.23.6)
- MySQL 5.7+ or MySQL 8.0+
- Make (for build commands)

Option 1: Download Pre-built Binary (Recommended)

Download the latest release for your platform:

curl -L https://github.com/koh/mysql-mcp-server/releases/latest/download/mysql-mcp-server-linux-amd64.tar.gz | tar xz chmod +x mysql-mcp-server sudo mv mysql-mcp-server /usr/local/bin/
curl -L https://github.com/koh/mysql-mcp-server/releases/latest/download/mysql-mcp-server-darwin-arm64.tar.gz | tar xz chmod +x mysql-mcp-server mv mysql-mcp-server /usr/local/bin/
curl -L https://github.com/koh/mysql-mcp-server/releases/latest/download/mysql-mcp-server-darwin-amd64.tar.gz | tar xz chmod +x mysql-mcp-server mv mysql-mcp-server /usr/local/bin/
# Download from https://github.com/koh/mysql-mcp-server/releases/latest # Extract mysql-mcp-server-windows-amd64.zip # Add to PATH or move mysql-mcp-server.exe to a directory in PATH
git clone https://github.com/koh/mysql-mcp-server.git cd mysql-mcp-server
make build # Or use make setup for full development setup

After installation, verify the server is accessible:

The server uses environment variables for MySQL connection configuration:

- MYSQL_HOST: MySQL server host (default: localhost)
- MYSQL_PORT: MySQL server port (default: 3306)
- MYSQL_USER: MySQL username
- MYSQL_PASSWORD: MySQL password
- MYSQL_DATABASE: Database name to connect to

You can copy.env.exampleto.envand modify it with your credentials:

Add the server to your Claude Desktop configuration file:

macOS:~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:%APPDATA%\Claude\claude_desktop_config.json

{ "mcpServers": { "mysql": { "command": "mysql-mcp-server", "env": { "MYSQL_HOST": "localhost", "MYSQL_PORT": "3306", "MYSQL_USER": "your_user", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database" } } } }
export MYSQL_HOST=localhost export MYSQL_PORT=3306 export MYSQL_USER=root export MYSQL_PASSWORD=password export MYSQL_DATABASE=testdb ./mysql-mcp-server

Execute SELECT queries to retrieve data from MySQL database. This tool is restricted to SELECT statements only for safety. Use theexecutetool for data modification operations.

- query(required): SELECT statement only
- format(optional): Output format -json,table,csv, ormarkdown(default:table)

{ "name": "query", "arguments": { "query": "SELECT  FROM users WHERE status = 'active' LIMIT 10", "format": "csv" } }

Execute INSERT, UPDATE, DELETE queries with safety checks. This tool implements a two-step execution process for safety:
- First run withdry_run=trueto preview affected rows
- Then run withdry_run=falseand the confirmation token to execute

- sql(required): INSERT, UPDATE, or DELETE statement
- dry_run(optional): If true, shows affected rows without executing (default: true)
- confirm_token(optional): Token from dry-run response, required when dry_run=false

{ "name": "execute", "arguments": { "sql": "UPDATE users SET status = 'inactive' WHERE last_login < '2024-01-01'", "dry_run": true } }
{ "content": [ {"type": "text", "text": "DRY RUN - Operation: UPDATE"}, {"type": "text", "text": "This operation will affect 42 rows"}, {"type": "text", "text": "To execute this query, run again with dry_run=false and the confirmation token below:"}, {"type": "text", "text": "confirm_token: abc123def456"} ], "affected_rows": 42, "operation": "UPDATE", "confirm_token": "abc123def456" }
{ "name": "execute", "arguments": { "sql": "UPDATE users SET status = 'inactive' WHERE last_login < '2024-01-01'", "dry_run": false, "confirm_token": "abc123def456" } }
{ "name": "schema", "arguments": { "table": "users" } }
{ "name": "tables", "arguments": {} }

Analyze the execution plan of a MySQL query to understand performance. Supports both EXPLAIN and EXPLAIN ANALYZE.

- query(required): The SQL query to analyze
- analyze(optional): If true, runs EXPLAIN ANALYZE to get actual execution statistics (default: false)

{ "name": "explain", "arguments": { "query": "SELECT  FROM users WHERE email = 'test@example.com'" } }
{ "name": "explain", "arguments": { "query": "SELECT * FROM users WHERE age > 25", "analyze": true } }

Note:EXPLAIN ANALYZE actually executes the query to gather real execution statistics, including actual row counts and timing information. Use with caution on queries that modify data or take a long time to execute.

{ "mcp.servers": { "mysql": { "command": "/path/to/mysql-mcp-server", "env": { "MYSQL_HOST": "localhost", "MYSQL_USER": "root", "MYSQL_PASSWORD": "password", "MYSQL_DATABASE": "mydb" } } } }

Create a custom extension that spawns the MCP server. SeeINTEGRATION.mdfor implementation details.

Cursor supports MCP servers through its configuration:
- Open Cursor Settings
- Navigate to "AI" → "Model Context Protocol"
- Add server configuration:

{ "mysql": { "command": "/path/to/mysql-mcp-server", "env": { "MYSQL_HOST": "localhost", "MYSQL_USER": "root", "MYSQL_PASSWORD": "password", "MYSQL_DATABASE": "mydb" } } }

GitHub Copilot doesn't directly support MCP servers, but you can create a bridge through VSCode extensions. SeeINTEGRATION.mdfor detailed implementation.

For any tool that supports subprocess communication:

const { spawn } = require('child_process'); class MCPClient { constructor(serverPath, env) { this.server = spawn(serverPath, [], { env }); // ... handle communication } async callTool(name, arguments) { return this.request('tools/call', { name, arguments }); } } // Usage const client = new MCPClient('/path/to/mysql-mcp-server', { MYSQL_HOST: 'localhost', MYSQL_USER: 'root', MYSQL_PASSWORD: 'password', MYSQL_DATABASE: 'mydb' });

For complete integration examples and troubleshooting, seeINTEGRATION.md.

For detailed testing instructions, seeTESTING.md.

# Setup and run interactive test client make setup make test-client

- Thequerytool is restricted to SELECT statements only to prevent accidental data modification
- Theexecutetool requires a two-step confirmation process for all data modification operations
- Never expose this server to untrusted clients
- Use appropriate MySQL user permissions
- Consider using read-only database users when possible
- The dry-run feature allows you to preview the impact of UPDATE/DELETE operations before execution
- Confirmation tokens expire after 5 minutes for security
- Keep your database credentials secure

Multi-database agent access (PostgreSQL, SQLite, MySQL, Oracle, SQL Server) with batch queries, pre-configured connections, and SQLGlot-enforced read-only safety

A read-only MCP server for MySQL, enabling LLMs to query live data using the CData JDBC Driver.

Database MCP server for MySQL, MariaDB, PostgreSQL & SQLite

A single-binary MCP server for MySQL, MariaDB, PostgreSQL, and SQLite

A Model Context Protocol (MCP) server that provides multi-database query execution capabilities with support for SQLite, PostgreSQL, and MySQL databases. Includes a built-in Web UI for managing database connections.

Allows Claude AI to interact directly with MySQL databases.

Update various databases (PostgreSQL, MySQL, MongoDB, SQLite) using data from CSV and Excel files.

Enables AI assistants to interact with various databases through JDBC connections.

An MCP server for retrieving data from a MariaDB database.

Access and manage MariaDB or MySQL databases using an MCP server.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.