MySQL MCP Server
Provides tools for querying, exploring schemas, executing SQL with permission controls, listing tables, describing structures, and browsing databases in a MySQL database.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MySQL MCP Serverlist all tables in the database"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MySQL MCP Server
A Model Context Protocol (MCP) server for MySQL databases, built with NestJS and MCP-Nest. Enables AI assistants like Claude and Cursor to interact with MySQL databases through a standardized protocol.
Overview
MySQL MCP Server exposes MySQL database operations as MCP tools, allowing AI assistants to:
Query and explore database schemas
Execute SQL queries with permission controls
List tables, describe table structures, and browse databases
Run in multiple transport modes (stdio, HTTP SSE, Streamable HTTP)
Features
Description | |
Connection Pool | Efficient MySQL connection management with configurable pool size |
Permission Control | Granular SQL operation permissions (SELECT, INSERT, UPDATE, DELETE, DDL) |
DRY_RUN Mode | Validate SQL queries without returning actual data |
MCP Tools | Standardized database operations exposed via Model Context Protocol |
Graceful Shutdown | Clean resource cleanup on process termination |
File Logging | Configurable log output with rotation support |
Prerequisites
Node.js 18+
MySQL 5.7+ database
npm or pnpm package manager
Installation
# Global installation (recommended)
npm install -g @johnson.lee/mysql-mcp-server
# Or use npx
npx @johnson.lee/mysql-mcp-serverQuick Start
# Set environment variables
export DB_HOST=localhost
export DB_PORT=3306
export DB_USER=root
export DB_PASSWORD=your_password
export DB_NAME=your_database
# Run the server
mysql-mcpConfiguration
Configure via environment variables:
Database Connection
Variable | Default | Description |
| localhost | MySQL host |
| 3306 | MySQL port |
| root | MySQL user |
| - | MySQL password |
| test_db | Database name |
| 2 | Min pool connections |
| 10 | Max pool connections |
Permission Control
Variable | Default | Description |
| true | Allow SELECT queries |
| true | Allow SHOW / DESCRIBE |
| false | Allow INSERT |
| false | Allow UPDATE |
| false | Allow DELETE |
| false | Allow CREATE/ALTER/DROP/TRUNCATE |
Server Options
Variable | Default | Description |
| mysql-mcp-server | Server name — used as log file prefix |
| stdio | Transport: stdio/http-sse/streamable-http |
| info | Log level: debug/info/warn/error |
| ./logs | Log directory |
| false | Validate SQL without returning data |
Editor Integration
Claude Desktop
Edit ~/.config/claude/claude_desktop_config.json:
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["@johnson.lee/mysql-mcp-server"],
"env": {
"DB_HOST": "localhost",
"DB_USER": "root",
"DB_PASSWORD": "your_password",
"DB_NAME": "your_database"
}
}
}
}Cursor
Create .cursor/mcp.json:
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["@johnson.lee/mysql-mcp-server"],
"env": {
"DB_HOST": "localhost",
"DB_USER": "root",
"DB_PASSWORD": "your_password",
"DB_NAME": "your_database"
}
}
}
}Multi-Environment Setup
You can register multiple instances to connect different databases simultaneously.
Each instance should have a unique MCP_SERVER_NAME, which is also used as the log file prefix — e.g. dev-info.log, prod-error.log.
Note: All
envvalues must be strings. Use"true"/"false", not bare booleans.
{
"mcpServers": {
"dev-mysql": {
"command": "npx",
"args": ["@johnson.lee/mysql-mcp-server"],
"env": {
"MCP_SERVER_NAME": "dev",
"DB_HOST": "dev-db.example.com",
"DB_PORT": "3306",
"DB_USER": "dev_user",
"DB_PASSWORD": "dev_password",
"DB_NAME": "dev_db",
"LOG_DIR": "/tmp/mcp-logs"
}
},
"prod-mysql": {
"command": "npx",
"args": ["@johnson.lee/mysql-mcp-server"],
"env": {
"MCP_SERVER_NAME": "prod",
"DB_HOST": "prod-db.example.com",
"DB_PORT": "3306",
"DB_USER": "prod_user",
"DB_PASSWORD": "prod_password",
"DB_NAME": "prod_db",
"LOG_DIR": "/tmp/mcp-logs",
"DRY_RUN": "true"
}
}
}
}With the above config, log files are written to LOG_DIR with the server name as prefix:
/tmp/mcp-logs/
├── dev-info.log
├── dev-error.log
├── prod-info.log
└── prod-error.logAvailable Tools
list_tables
List all tables in the current database.
describe_table
Get table structure (columns, types, keys, etc.).
{
"name": "describe_table",
"arguments": { "tableName": "users" }
}execute_query
Execute SQL queries.
{
"name": "execute_query",
"arguments": { "sql": "SELECT * FROM users LIMIT 10" }
}list_databases
List all available databases on the MySQL server.
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/CobaltBlue3699/mysql-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server