A fully featured Model Context Protocol (MCP) server for MySQL β designed to empower AI assistants, LLMs (like ChatGPT, Claude, Gemini), and automation tools with deep MySQL database access, diagnostics, and intelligent control.
β‘ Ideal for building AI-powered database agents, DevOps automation, or managing MySQL with natural language.
- GitHub: mcp-mysql-server
- Author: @mukul975
- License: MIT
- Keywords:
MySQL
,MCP Server
,AI MySQL interface
,LLM database tool
,MySQL automation
,chatbot SQL
This MySQL MCP Server provides LLMs and AI tools with:
- β
Secure Query Execution: Handles
SELECT
,INSERT
,UPDATE
,DELETE
, etc. with read-only validation. - π Schema Introspection: List tables, inspect structures, indexes, keys.
- π Performance Diagnostics: Analyze fragmentation, slow queries, buffer pool stats.
- π‘οΈ Security Auditing: Manage users, audit SSL, monitor roles & privileges.
- π§© Backup & Replication Monitor: View replication lag, log status, recovery readiness.
- βοΈ System Monitoring: Get process list, memory usage, plugin state.
- π Query Insights: Index recommendations, event scheduler overview.
pip install -r requirements.txt
# Or install manually:
pip install "mcp[cli]"
pip install mysql-connector-python
Variable | Description | Default |
---|---|---|
MYSQL_HOST |
MySQL server hostname | localhost |
MYSQL_PORT |
MySQL port | 3306 |
MYSQL_USER |
Username | root |
MYSQL_PASSWORD |
Password | (empty) |
MYSQL_DATABASE |
Target DB | (empty) |
π‘ Use
.env
or export variables manually
python mysql_server.py # Default (stdin transport)
python mysql_server.py --transport sse # For web clients (SSE)
python mysql_server.py --help # Command help
{
"mcpServers": {
"mysql": {
"command": "python",
"args": ["path/to/mysql_server.py"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_pass",
"MYSQL_DATABASE": "your_db"
}
}
}
}
list_tables
: Lists all tablesdescribe_table
: Schema of a specific tableexecute_sql
: Run select or data modification queriesmysql_slow_query_analysis
: Detect slow queriesmysql_user_privileges
: Audit user accessmysql_replication_lag_monitoring
: Check lag in replication
Access tools via code or LLM prompts:
mysql_query
,list_mysql_tables
,mysql_table_schema
mysql_index_optimization_suggestions
,mysql_deadlock_detection
mysql_ssl_tls_configuration_audit
,mysql_backup_health_check
mysql_server_health_dashboard
,mysql_event_scheduler
, and dozens more
- Store secrets in env vars or vault
- Do not expose server publicly
- Privilege validation and SSL audit included
- Connection errors
- SQL syntax issues
- Network timeouts
- Returns structured error response
mcp-mysql-server/
βββ mysql_server.py # Entry point
βββ requirements.txt # Dependencies
βββ README.md # Docs
βββ pyproject.toml # Project metadata (optional)
- Ensure MySQL is running
- Set environment vars
- Run
python mysql_server.py
- Try with
mcp dev mysql_server.py
(if using MCP CLI)
- Fork the repo
- Create feature/bug branches
- Submit PRs with description & tests
Q: What is MCP? A: Model Context Protocol (MCP) is an interface to give LLMs access to structured tools like databases, APIs, and system utilities.
Q: Can I use this with ChatGPT or Claude? Yes! It's designed for direct integration with AI/LLM tools that support tool-use or system-level automation.
Q: Is it safe to run this in production? It depends on your environment. Always restrict access, use read-only roles, and monitor logs.
MIT License β Open source and free to use.
- Share on Reddit r/MachineLearning
- Post to LinkedIn or Twitter with GIF or screenshots
- Submit to awesome-LLM or similar curated lists
Let me know if you need an HTML version, web preview, or GitHub Pages site for this!