- MCP Server MySQL Database Explorer
MCP Server MySQL Database Explorer
MCP Server MySQL Database Explorer
This MCP server connects to your MySQL database, providing seamless access to database schemas, tables, and query capabilities through LLMs.
Features
-
Connect to your MySQL database
-
Expose table schemas, create statement and Sample data as resources
-
Run read-only SQL queries with secure validation
Setup Instructions
-
Install Dependencies
pip install "mcp[cli]" aiomysql
-
Configure Environment Variables
Create a .env file with your database credentials:
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=YOUR_PASSWORD
MYSQL_DB=YOUR_DB
MYSQL_POOL_SIZE=10
Or set these variables directly in your environment.
-
**Run in MCP interceptor
uv run mcp dev main.py
Navigate to http://127.0.0.1:6274/, then change the argument to this:
run --env-file=.env main.py
Click "Connect" to test the server
- **Install the MCP Server in MCP Client (e.g. Cline, Cursor)
Paste the JSON setting to your MCP Client:
{
"mcpServers": {
"mysql-mcp-server": {
"command": "uv",
"args": [
"--directory",
"/Your/Directory/to/the/project/root",
"run",
"main.py"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "YOUR_PASSWORD",
"MYSQL_DB": "YOUR_DB",
"MYSQL_POOL_SIZE": "10"
}
}
}
}
Usage
Once installed, you can interact with your database through your LLMs with MCP Client: