MySQL MCP Server
Query MySQL databases, list tables, and inspect schemas from your AI assistant
The MySQL MCP Server connects Claude and other MCP-compatible agents directly to a MySQL or MariaDB database. Ask natural-language questions, run SQL queries, explore table schemas, and iterate on results — without leaving your AI chat session. Supports both read and write operations depending on your database user's privileges.
Installation & Configuration
Add this block to your claude_desktop_config.json (or your agent framework's MCP config file):
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@benborla29/mcp-server-mysql"],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_user",
"MYSQL_PASS": "your_password",
"MYSQL_DB": "your_database"
}
}
}
}
Config file location:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/claude/claude_desktop_config.json
Creating a read-only MySQL user (recommended):
CREATE USER 'mcp_ro'@'localhost' IDENTIFIED BY 'strong_password';
GRANT SELECT ON your_database.* TO 'mcp_ro'@'localhost';
FLUSH PRIVILEGES;
Available Tools (4)
queryexecutelist_tablesdescribe_table
Use Cases
- Natural-language analytics — ask "how many users signed up last week?" and get real SQL results
- Schema exploration — have Claude explain an unfamiliar database schema in plain English
- Data debugging — quickly inspect rows and columns while debugging application issues
- Query generation — let Claude write and iterate on complex JOINs or aggregations for you
Gotchas
- MYSQL_HOST must be an IP, not localhost: On some systems
localhostresolves to a Unix socket, which Node.js mysql2 handles differently. Use127.0.0.1to force TCP if you see connection errors. - Port must be a string: The
MYSQL_PORTenv var is parsed as a string in the config JSON — passing an integer literal causes a type error in some MCP hosts. - The
executetool runs writes: Unlikequery,executewill happily runDELETEorDROPstatements. If you're using a write-enabled user, be explicit in your prompt about what you want. - Remote databases need firewall rules: If your MySQL instance is not on localhost, ensure the MCP host IP is whitelisted in MySQL's
bind-addressand any network firewall rules.
Security Note
Always connect with a dedicated read-only MySQL user unless you explicitly need writes. An AI assistant connected to a write-enabled production database can issue destructive queries. Never expose your root or admin credentials. Restrict the database user to only the schemas it needs with GRANT SELECT ON specific_db.*.
Source & Documentation
GitHub Repository: https://github.com/benborla/mcp-server-mysql
Protocol: Model Context Protocol (MCP) — modelcontextprotocol.io
20 ready-to-paste server configs + installer + doctor script