Content
# MySQL Readonly MCP Server
This is a MySQL read-only query server based on MCP (Model Context Protocol), which allows access to the MySQL database through a secure read-only query interface.
## Features
- Supports read-only query operations for MySQL databases
- Manages database connections using a connection pool
- Automatically limits the number of query results
- Supports parameterized queries
- Provides formatted query result output
- Built-in security checks to prevent non-read-only operations
## Environment Requirements
- Python 3.10+
- MySQL 5.7+
- aiomysql
## Installation
```bash
git clone https://github.com/the-nine-nation/mysql-mcp.git
pip install -e .
```
## Usage
For example, place the following dictionary in config.json: where sys.executable is the executable file of the Python virtual environment, usually named python, and can be used under conda or uv.
mysql_mcp_py is the absolute path of the main.py file.
```json
"mysql": {
"command": sys.executable,
"args": [mysql_mcp_py],
"env": {
"MYSQL_ENABLED": "true",
"MYSQL_HOST": "IP address of the MySQL database",
"MYSQL_PORT": "Port of the MySQL database",
"MYSQL_DATABASE": "Name of the MySQL database",
"MYSQL_USERNAME": "Username for the MySQL database",
"MYSQL_PASSWORD": "Password for the MySQL database",
"MYSQL_POOL_MINSIZE": "1",
"MYSQL_POOL_MAXSIZE": "10",
"MYSQL_RESOURCE_DESC_FILE": "Path to the resource description file for the MySQL database"
}
}
```
Please note:
1. MYSQL_RESOURCE_DESC_FILE is a description file that can include some information from the database, such as what each table is used for, which can enhance the model's understanding capabilities.
2. MYSQL_ENABLED can be left unspecified by default.
## Security Features
- Only allows read-only operations
- Prevents multi-statement execution
- Automatically limits the number of query results
- Uses parameterized queries to prevent SQL injection
## Considerations
- Ensure that the database user has only read-only permissions
- The resource description file is required to define the available query interfaces
- The default limit for query results is 20 rows, which can be adjusted through environment variables
## Contribution
Feel free to submit Issues and Pull Requests.
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.
TrendRadar
TrendRadar: Your hotspot assistant for real news in just 30 seconds.
mempalace
The highest-scoring AI memory system ever benchmarked. And it's free.
mempalace
The highest-scoring AI memory system ever benchmarked. And it's free.