py-mcp-mysql
Configuration
View docs{
"mcpServers": {
"amornpan-py-mcp-mysql": {
"command": "python",
"args": [
"-m",
"src.mysql_mcp_server.server"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_DATABASE": "your_database",
"MYSQL_PASSWORD": "your_password"
}
}
}
}You can securely interact with MySQL databases through a dedicated MCP server that lets you list tables, read table data, and execute SQL queries in a controlled, auditable way. This makes database exploration safer and more structured for AI assistants and automation.
Use an MCP client to connect to the MySQL MCP Server and perform common actions such as listing available tables, reading contents, and running SQL queries. The server exposes a safe interface that logs operations and enforces access controls based on the environment configuration you provide.
Prerequisites you need before starting: a Python 3.x runtime and internet access to install dependencies.
Option 1: Run the MCP server as a standalone process.
Step 1: Install dependencies from the requirements file.
Step 2: Start the MCP server using the Python module path.
Configure the following environment variables to connect to your MySQL database: MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASSWORD, and MYSQL_DATABASE. Provide values that reflect your database instance and follow the principle of least privilege by using a dedicated user account with only the necessary permissions.
To integrate with Claude Desktop, provide the MCP server configuration in your client setup, including the Python command to run and the required environment variables. For production deployments, enable comprehensive logging and consider implementing query whitelisting and access restrictions to protect your data.
Security Best Practices: Create a dedicated MySQL user with minimal permissions, avoid root credentials, restrict access to necessary operations, enable audit logging, and regularly review database access.
{
"mcpServers": {
"mysql": {
"command": "python",
"args": [
"-m",
"src.mysql_mcp_server.server"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}# Clone the repository
git clone https://github.com/designcomputer/mysql_mcp_server.git
cd mysql_mcp_server
# Install dependencies
pip install -r requirements.txt
# Run the server
python -m src.mysql_mcp_server.server
```,
"items":null,Never commit environment variables or credentials. Use a dedicated MySQL user with minimal permissions and monitor all database operations.
MIT License - see LICENSE file for details.
Follow standard contribution steps: fork, create a feature branch, commit changes, push, and open a pull request.
List available MySQL tables as resources exposed by the MCP server.
Read and return the contents of a specified MySQL table.
Execute a SQL query against the configured MySQL database with appropriate error handling.
Comprehensive logging of all database operations for auditing and troubleshooting.