
MCP MySQL Server
Enables interaction with MySQL databases (including AWS RDS and cloud instances) through natural language. Supports database connections, query execution, schema inspection, and comprehensive database management operations.
README
MCP MySQL Server
A Model Context Protocol (MCP) server for MySQL databases, including support for AWS RDS and other cloud MySQL instances. This server provides comprehensive database management capabilities through a standardized MCP interface.
📋 Quick Start for VS Code Users: See VSCODE_SETUP.md for step-by-step VS Code and GitHub Copilot integration instructions.
Features
- ✅ Database Connection Management: Connect to local MySQL or cloud instances (AWS RDS, Google Cloud SQL, etc.)
- ✅ Query Execution: Execute SQL queries with prepared statement support
- ✅ Schema Inspection: List databases, tables, and describe table structures
- ✅ Index Management: View table indexes and statistics
- ✅ Security: Secure connection handling with SSL support
- ✅ Error Handling: Comprehensive error reporting and connection management
Installation
From NPM (Recommended)
npm install -g @sajithrw/mcp-mysql@1.0.0
Or run ad‑hoc without global install using npx
(shown later in config).
From Source
git clone https://github.com/sajithrw/mcp-mysql.git
cd mcp-mysql
npm install
npm run build
Configuration
VS Code (mcp.json) Setup (Recommended)
Create (or update) .vscode/mcp.json
in your project or in your global VS Code user settings folder. Use the published package via npx
so you always invoke the correct version.
{
"servers": {
"mcp-mysql": {
"type": "stdio",
"command": "npx",
"args": [
"@sajithrw/mcp-mysql@1.0.0"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}
Then:
- Reload VS Code window (Command Palette: "Developer: Reload Window").
- Open Command Palette and run: "MCP: Start Server" (pick
mcp-mysql
). - Use Copilot / MCP clients to call tools (e.g., ask to list tables).
Previous
settings.json
basedgithub.copilot.advanced.mcp
configuration is deprecated in favor ofmcp.json
discovery.
Alternative: Local Build Path
If working from a local clone/build instead of the published package:
{
"servers": {
"mcp-mysql": {
"type": "stdio",
"command": "node",
"args": ["/absolute/path/to/mcp-mysql/build/index.js"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password"
}
}
}
}
Using with Claude Desktop
Add the server to your Claude Desktop configuration:
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["@sajithrw/mcp-mysql@1.0.0"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password"
}
}
}
}
Using with MCP Inspector
For testing and development:
npx @modelcontextprotocol/inspector npx @sajithrw/mcp-mysql@1.0.0
Using with VS Code and GitHub Copilot
Once configured, you can use the MySQL MCP server with GitHub Copilot in VS Code to interact with your databases using natural language.
Example Interactions
-
Database Exploration:
- "Show me all tables in the database"
- "Describe the structure of the users table"
- "What indexes are on the products table?"
-
Data Analysis:
- "Show me the top 10 customers by order count"
- "Find all users created in the last 30 days"
- "Get statistics about the orders table"
-
Schema Management:
- "List all databases on this server"
- "Show me table sizes and row counts"
- "Find tables with specific column names"
Step-by-Step (Recap)
- Create
.vscode/mcp.json
with config above. - Reload VS Code window.
- Run "MCP: Start Server".
- Use Copilot Chat / MCP-aware client to issue requests.
Troubleshooting Quick Tips
- Ensure the package version (
1.0.0
) matches what you intend to use. - If the server won't start, run it manually:
npx @sajithrw/mcp-mysql@1.0.0
to see logs. - Verify environment variables are present (you can also place them in a
.env
if your shell loads them before launching VS Code).
Available Tools
1. mysql_connect
Connect to a MySQL database.
Parameters:
host
(required): MySQL server hostname or IP addressport
(optional): MySQL server port (default: 3306)user
(required): Database usernamepassword
(required): Database passworddatabase
(optional): Database name to connect tossl
(optional): Use SSL connection (default: false)
Example:
{
"host": "localhost",
"port": 3306,
"user": "myuser",
"password": "mypassword",
"database": "mydb",
"ssl": false
}
2. mysql_query
Execute a SQL query on the connected database.
Parameters:
query
(required): SQL query to executeparameters
(optional): Array of parameters for prepared statements
Examples:
Simple query:
{
"query": "SELECT * FROM users LIMIT 10"
}
Prepared statement:
{
"query": "SELECT * FROM users WHERE age > ? AND city = ?",
"parameters": ["25", "New York"]
}
3. mysql_list_databases
List all databases on the MySQL server.
Parameters: None
4. mysql_list_tables
List all tables in the current or specified database.
Parameters:
database
(optional): Database name (uses current database if not specified)
5. mysql_describe_table
Get the structure/schema of a specific table.
Parameters:
table
(required): Table name to describedatabase
(optional): Database name (uses current database if not specified)
6. mysql_show_indexes
Show indexes for a specific table.
Parameters:
table
(required): Table name to show indexes fordatabase
(optional): Database name (uses current database if not specified)
7. mysql_get_table_stats
Get statistics about a table (row count, size, etc.).
Parameters:
table
(required): Table name to get statistics fordatabase
(optional): Database name (uses current database if not specified)
8. mysql_disconnect
Disconnect from the MySQL database.
Parameters: None
Common Use Cases
1. Connecting to AWS RDS
{
"host": "mydb.abc123.us-west-2.rds.amazonaws.com",
"port": 3306,
"user": "admin",
"password": "mypassword",
"database": "production",
"ssl": true
}
2. Exploring Database Schema
- Connect to database using
mysql_connect
- List all databases with
mysql_list_databases
- List tables with
mysql_list_tables
- Describe specific tables with
mysql_describe_table
- Check indexes with
mysql_show_indexes
3. Data Analysis
- Connect to database
- Execute analytical queries with
mysql_query
- Get table statistics with
mysql_get_table_stats
Security Considerations
- Credentials: Never hardcode database credentials. Use environment variables or secure configuration management.
- SSL/TLS: Always use SSL when connecting to production databases or cloud instances.
- Permissions: Use database users with minimal required permissions.
- Query Validation: The server uses prepared statements to prevent SQL injection.
Environment Variables
You can set default connection parameters using environment variables:
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=myuser
export MYSQL_PASSWORD=mypassword
export MYSQL_DATABASE=mydb
export MYSQL_SSL=true
Development
Building
npm run build
Testing
npm run test
Development Mode
npm run dev
Troubleshooting
Connection Issues
- Connection Refused: Check that MySQL server is running and accessible
- Authentication Failed: Verify username and password
- SSL Errors: Ensure SSL is properly configured on both client and server
- Timeout: Check network connectivity and firewall settings
Common Error Messages
"Not connected to MySQL"
: Usemysql_connect
before executing other commands"Query execution failed"
: Check SQL syntax and table/column names"Connection failed"
: Verify connection parameters and network connectivity
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details.
Support
Related Projects
推荐服务器

Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。