Content
# mcp-mysql-server
A MySQL database operation server based on the Model Context Protocol. This server enables AI models to interact with MySQL databases through a standardized interface.
## Installation
```bash
npx @malove86/mcp-mysql-server
```
## Configuration
The server supports two deployment modes:
### 1. Local Run Mode
Run using the command line in the MCP settings configuration file:
```json
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@malove86/mcp-mysql-server"],
"env": {
"MYSQL_HOST": "your_host",
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database",
"MYSQL_PORT": "3306"
}
}
}
}
```
### 2. Remote URL Mode (v0.2.2+)
Pointing to a remotely running MCP server:
```json
{
"mcpServers": {
"mcp-mysql-server": {
"url": "http://your-server-address:port/mcp-mysql-server"
}
}
}
```
On the remote server, you need to set the environment variables and then start the MCP server:
```bash
# Set environment variables
export MYSQL_HOST=your_host
export MYSQL_USER=your_user
export MYSQL_PASSWORD=your_password
export MYSQL_DATABASE=your_database
export MYSQL_PORT=3306 # Optional, defaults to 3306
# Start the server
npx @malove86/mcp-mysql-server
```
> Note: MYSQL_PORT is optional, with a default value of 3306.
## Version Features
### New Features in v0.2.4+
- **Multi-user Concurrent Support**: The server can now handle requests from multiple users simultaneously.
- **Efficient Connection Pool Management**: Improved connection pool supports up to 50 concurrent connections.
- **Request-level Isolation**: Each request has a unique identifier for easier tracking and debugging.
- **Detailed Logging**: Logs the execution process and resource usage of each request.
- **Improved Error Handling**: More precise capture and reporting of database errors.
- **Performance Optimization**: Connection pool reuse and optimized connection management enhance processing speed.
### Features in v0.2.2+
- **Automatic Database Connection**: The server will automatically attempt to connect to the database if environment variables are set at startup.
- **No Client Parameters Required**: When using URL mode, clients do not need to provide database connection information.
- **Seamless Database Operations**: Tools like `list_tables` and `query` can be used directly without first calling `connect_db`.
- **More Secure**: Sensitive database credentials exist only on the server side and are not exposed in client interactions.
- **Graceful Fault Tolerance**: Subsequent operations will automatically retry connections even if the initial connection fails.
## Available Tools
### 1. connect_db
Establish a connection to the MySQL database using the provided credentials. This tool is optional if the connection has already been set via environment variables.
```json
{
"host": "localhost",
"user": "root",
"password": "your_password",
"database": "your_database",
"port": 3306 // Optional, defaults to 3306
}
```
### 2. query
Execute a SELECT query, supporting optional prepared statement parameters.
```json
{
"sql": "SELECT * FROM users WHERE id = ?",
"params": [1] // Optional parameters
}
```
### 3. list_tables
List all tables in the connected database.
```json
{} // No parameters needed from v0.2.4 onwards
```
### 4. describe_table
Get the structure of a specific table.
```json
{
"table": "users"
}
```
## Features
- Secure connection handling with automatic cleanup
- Support for prepared statement parameters
- Comprehensive error handling and validation
- TypeScript support
- Automatic connection management
- Server environment variable configuration
- Support for URL remote connection mode
- Multi-user concurrent support
- High-performance connection pool
## Performance
- Supports up to 50 concurrent connections (configurable)
- Automatic management of connection pools to improve resource utilization
- Detailed request tracking and performance monitoring
## Security
- Uses prepared statements to prevent SQL injection
- Supports secure password handling through environment variables
- Validates queries before execution
- Automatically closes connections after completion
- Sensitive credentials are not exposed in client interactions in URL mode
- Connection isolation to prevent data leakage between users
## Contribution
Contributions are welcome! Please feel free to submit Pull Requests to https://github.com/Malove86/mcp-mysql-server.git
## License
MIT
Connection Info
You Might Also Like
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
markitdown
Python tool for converting files and office documents to Markdown.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
UnrealClientProtocol
Lightweight UE5 plugin that exposes Unreal Engine's reflection system over...
excalidraw-architect-mcp
An MCP server that generates beautiful Excalidraw architecture diagrams with...
claude-code-studio
Full-featured web workspace for Claude Code — chat, Kanban task board,...