mcp-server-mysql
v1.0.42
Published
MCP server for interacting with MySQL databases (READ-ONLY) with optimized caching
Downloads
2,158
Maintainers
Readme
MCP Server MySQL
MCP server for interacting with MySQL databases with read-only query support.
Requirements
- Node.js 20 or higher is required
- MySQL database connection
Quick Start
Step 1: Install Node.js 20
You need Node.js 20 or higher. Choose one of the following methods:
Option A: Using nvm (Recommended)
If you have nvm installed:
nvm install 20
nvm use 20If you don't have nvm, install it first:
- macOS/Linux:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash - Windows: Use nvm-windows
Option B: Direct Installation
Download and install Node.js 20 from nodejs.org
Step 2: Verify Node.js Version
node --versionShould show v20.x.x or higher.
Step 3: Configure MCP in Cursor
Add to your ~/.cursor/mcp.json:
Single Database Configuration
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "mcp-server-mysql@latest"],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASS": "your_password",
"MYSQL_DB": "your_database"
}
}
}
}Step 4: Restart Cursor
After configuring, restart Cursor to load the MCP server.
Troubleshooting
Error: "This package requires Node.js 20 or higher"
Solution:
If using nvm:
nvm install 20 nvm use 20Then restart Cursor.
If not using nvm:
- Install Node.js 20 from nodejs.org
- Make sure Node.js 20 is in your PATH
- Restart your terminal and Cursor
Verify installation:
node --versionShould show
v20.x.xor higher.
Server closes immediately
- Check MySQL connection settings in your MCP config
- Ensure MySQL server is running
- Verify database credentials are correct
Environment Variables
Database Connection
MYSQL_HOST- MySQL host (default: 127.0.0.1)MYSQL_PORT- MySQL port (default: 3306)MYSQL_USER- MySQL username (default: root)MYSQL_PASS- MySQL passwordMYSQL_DB- MySQL database name (optional, enables multi-DB mode if not set)MYSQL_SOCKET_PATH- Unix socket path (alternative to host/port)MYSQL_SSL- Enable SSL (set to "true" to enable)
Multi-Instance Support
MCP_DB_NAME- Database identifier/name for multi-instance setups (optional)- Used to identify which database instance is active
- Appears in tool descriptions and logs
- Defaults to
MYSQL_DBvalue or "default" - Recommended when using multiple database configurations
Cache Configuration
TABLE_LIST_CACHE_TTL_MS- Cache TTL in milliseconds (default: 18000000 = 5 hours)ENABLE_TABLE_LIST_CACHE- Enable/disable caching (default: true, set to "false" to disable)
Other Configuration
ENABLE_LOGGING- Enable debug logging (set to "true" to enable)MYSQL_DISABLE_READ_ONLY_TRANSACTIONS- Disable read-only transactions (set to "true" to disable)
Features
- Read-only SELECT queries
- Multi-database mode support
- Automatic dependency installation via npx
- Node.js 20+ requirement with clear error messages
License
MIT
