mysql-mcp-server
Allows natural language interaction with MySQL databases, providing tools for executing SQL queries, exploring database schema, listing tables, describing table structures, and retrieving sample data.
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 proper Model Context Protocol (MCP) server that enables natural language interaction with MySQL databases.
Features
MCP Protocol Compliance: Implements the official Model Context Protocol specification
Direct SQL Execution: Execute raw SQL queries safely
Database Schema Exploration: Explore database structure and table information
MCP Tools: Expose database operations as MCP tools
MCP Resources: Provide database schema and data as MCP resources
MCP Prompts: Offer helpful prompts for database analysis
Error Handling: Comprehensive error handling and logging
Related MCP server: MCP MySQL Server
Prerequisites
Python 3.10+
MySQL Server
Ollama running with Llama 3.2 model
MCP-compatible client (Claude Desktop, Windsurf, etc.)
Setup
1. Install Dependencies
pip install -r requirements.txt2. Configure Environment
Copy the environment template and configure your database settings:
cp .env.example .envEdit .env with your MySQL database configuration:
# MySQL Database Configuration
DB_HOST=localhost
DB_USER=your_mysql_user
DB_PASSWORD=your_mysql_password
DB_NAME=your_database_name
DB_PORT=3306MCP Tools
The server exposes the following MCP tools:
execute_sql_query
Execute a SQL query and return the results.
Parameters:
query(string) - The SQL query to executeReturns: Formatted query results
list_tables
List all tables in the database.
Parameters: None
Returns: List of all tables
describe_table
Get detailed information about a specific table.
Parameters:
table_name(string) - Name of the table to describeReturns: Table structure and row count
get_table_data
Get sample data from a table.
Parameters:
table_name(string) - Name of the tablelimit(integer, optional) - Maximum rows to return (default: 10)
Returns: Sample data from the table
MCP Resources
The server provides the following MCP resources:
schema://database
Get the complete database schema as a resource.
schema://tables/{table_name}
Get schema information for a specific table.
data://tables/{table_name}
Get sample data from a table as a resource.
MCP Prompts
The server offers the following MCP prompts:
sql_query_assistant
Generate a prompt for helping with SQL query creation.
Parameters:
query_description(string) - Description of what you want to query
database_analysis_task
Generate a prompt for database analysis tasks.
Parameters:
analysis_goal(string) - What you want to analyze in the database
Running the Server
Development Mode
Run the server in development mode with MCP Inspector:
uv run mcp dev mcp_server.pyProduction Mode
Run the server with stdio transport:
python mcp_server.pyIntegration with MCP Clients
Claude Desktop
Open Claude Desktop configuration file:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
Add the server configuration:
{
"mcpServers": {
"mysql": {
"command": "python",
"args": ["/path/to/your/project/mcp_server.py"],
"env": {
"DB_HOST": "localhost",
"DB_USER": "your_mysql_user",
"DB_PASSWORD": "your_mysql_password",
"DB_NAME": "your_database_name"
}
}
}
}Restart Claude Desktop
Windsurf Editor
Open MCP settings in Windsurf
Add a new MCP server with the following configuration:
Name:
mysqlCommand:
pythonArgs:
/path/to/your/project/mcp_server.pyEnvironment variables: Your database configuration
Usage Examples
Direct SQL Queries
"Execute: SELECT * FROM users WHERE created_at > '2024-01-01'"
"Run: UPDATE products SET price = price * 1.1 WHERE category = 'electronics'"Database Exploration
"List all tables in the database"
"Describe the structure of the orders table"
"Show me sample data from the customers table"Testing
Use the provided test script to verify the server functionality:
python test_mcp_server.pyTroubleshooting
Common Issues
Database Connection Errors
Verify MySQL is running
Check database credentials in
.envEnsure the database exists
MCP Server Not Detected
Check server configuration in client settings
Verify the server script path is correct
Check for syntax errors in the server code
Debug Mode
Enable debug logging by setting the log level:
LOG_LEVEL=DEBUGSecurity Considerations
Never expose your
.envfile in productionUse database users with limited privileges
Consider using connection pooling for production
Validate all SQL queries to prevent injection attacks
Contributing
Fork the repository
Create a feature branch
Make your changes
Add tests if applicable
Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues and questions:
Check the troubleshooting section
Review MCP documentation at https://modelcontextprotocol.io
Open an issue in the project repository
This server cannot be installed
Maintenance
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/hanzala-sohrab/mysql-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server