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 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, and the default value is 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 at startup if environment variables are set.
- **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`.
- **Increased Security**: 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 parameter
}
```
### 3. list_tables
List all tables in the connected database.
```json
{} // No parameters needed starting from v0.2.4
```
### 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
You Might Also Like
MarkItDown MCP
markitdown-mcp is a lightweight MCP server for converting various URIs to Markdown.
Github
GitHub MCP Server connects AI tools to GitHub for code management and automation.

apisix
Apache APISIX is an API Gateway for managing APIs and microservices.
opik
Opik is a powerful tool for managing and optimizing machine learning experiments.

MCP Toolbox for Databases
MCP Toolbox for Databases is an open-source server simplifying database tool...

sqlglot
SQLGlot is a no-dependency SQL parser and transpiler supporting 30 dialects.