MCP MySQL Server
A MySQL server with DDL operations, permission control, and operation logging support.
Version History
v3.0.0 (Latest Version)
- ✅ Read-only Mode: New
READONLYenvironment variable - enables only SELECT and SHOW commands - ✅ Tool Prefix Support: New
TOOL_PREFIXenvironment variable for tool name isolation and config separation - ✅ Project Branding: New
PROJECT_NAMEenvironment variable for custom tool descriptions - ✅ Multi-instance Support: Full support for running multiple MySQL server instances with isolated configurations
- ✅ Default Log Path: Changed default log directory from
./logsto./.setting
v2.0.1
- ✅ DDL SQL Logging: Added dedicated DDL SQL operation logging to
ddl.sqlfile - ✅ New Tool: Added
get_ddl_sql_logstool for querying DDL operation history
v2.0.0
- ✅ Initial version with DDL operations support
- ✅ Permission control system
- ✅ Operation logging
- ✅ Connection pool management
Features
- ✅ SQL query execution (DDL and DML)
- ✅ Database information retrieval
- ✅ Operation logging
- ✅ Connection pool management
- ✅ Auto-reconnect mechanism
- ✅ Health check
- ✅ Error handling and recovery
Installation
Global Installation (Recommended)
npm install -g @liangshanli/mcp-server-mysql
Local Installation
npm install @liangshanli/mcp-server-mysql
Install from Source
git clone https://github.com/liliangshan/mcp-server-mysql.git
cd mcp-server-mysql
npm install
Configuration
Set environment variables:
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=root
export MYSQL_PASSWORD=your_password
export MYSQL_DATABASE=your_database
export READONLY=false
export ALLOW_DDL=true
export ALLOW_DROP=false
export ALLOW_DELETE=false
Quick Start
1. Install the Package
npm install -g @liangshanli/mcp-server-mysql
2. Configure Environment Variables
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=root
export MYSQL_PASSWORD=your_password
export MYSQL_DATABASE=your_database
export READONLY=false
export ALLOW_DDL=false
export ALLOW_DROP=false
export ALLOW_DELETE=false
3. Run the Server
mcp-server-mysql
Editor Integration
Cursor Editor Configuration
Create .cursor/mcp.json file in project root:
Single Instance Configuration
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["@liangshanli/mcp-server-mysql"],
"env": {
"MYSQL_HOST": "your_host",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database",
"READONLY": "false",
"ALLOW_DDL": "false",
"ALLOW_DROP": "false",
"ALLOW_DELETE": "false"
}
}
}
}
Multi-instance Configuration
{
"mcpServers": {
"mysql-prod": {
"command": "npx",
"args": ["@liangshanli/mcp-server-mysql"],
"env": {
"MYSQL_HOST": "prod.example.com",
"MYSQL_PORT": "3306",
"MYSQL_USER": "prod_user",
"MYSQL_PASSWORD": "prod_password",
"MYSQL_DATABASE": "prod_db",
"READONLY": "true",
"TOOL_PREFIX": "prod",
"PROJECT_NAME": "Production Environment"
}
},
"mysql-test": {
"command": "npx",
"args": ["@liangshanli/mcp-server-mysql"],
"env": {
"MYSQL_HOST": "test.example.com",
"MYSQL_PORT": "3306",
"MYSQL_USER": "test_user",
"MYSQL_PASSWORD": "test_password",
"MYSQL_DATABASE": "test_db",
"TOOL_PREFIX": "test",
"PROJECT_NAME": "Test Environment"
}
}
}
}
VS Code Configuration - .vscode/mcp.json Format
1. Install MCP extension for VS Code
2. Create .vscode/mcp.json file:
Single Instance Configuration
{
"servers": {
"mysql": {
"command": "npx",
"args": ["@liangshanli/mcp-server-mysql"],
"env": {
"MYSQL_HOST": "your_host",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}
Multi-instance Configuration
{
"servers": {
"mysql-prod": {
"command": "npx",
"args": ["@liangshanli/mcp-server-mysql"],
"env": {
"MYSQL_HOST": "prod.example.com",
"MYSQL_PORT": "3306",
"MYSQL_USER": "prod_user",
"MYSQL_PASSWORD": "prod_password",
"MYSQL_DATABASE": "prod_db",
"READONLY": "true",
"TOOL_PREFIX": "prod",
"PROJECT_NAME": "Production Environment"
}
},
"mysql-test": {
"command": "npx",
"args": ["@liangshanli/mcp-server-mysql"],
"env": {
"MYSQL_HOST": "test.example.com",
"MYSQL_PORT": "3306",
"MYSQL_USER": "test_user",
"MYSQL_PASSWORD": "test_password",
"MYSQL_DATABASE": "test_db",
"TOOL_PREFIX": "test",
"PROJECT_NAME": "Test Environment"
}
}
}
}