# mysql_mcp_server

> MCP Server

The MySQL MCP Server enables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface. This facilitates safer database

## Overview

- **Category:** Database
- **Language:** Python
- **Stars:** 1359
- **Forks:** 54
- **Owner:** designcomputer
- **GitHub:** https://github.com/designcomputer/mysql_mcp_server
- **Created:** 2024-12-03T20:53:52+00:00
- **Updated:** 2025-03-28T21:46:55+00:00
- **Source:** https://model-context-protocol.com/servers/mysql-secure-database-interaction-model-context

## Setup

## Setup

**Manual Installation**
```bash
pip install mysql-mcp-server
```

**Installing via Smithery**

To install MySQL Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/mysql-mcp-server):

```bash
npx -y @smithery/cli install mysql-mcp-server --client claude
```

**Configuration**

Set the following environment variables:

```bash
MYSQL_HOST=localhost     # Database host
MYSQL_PORT=3306         # Optional: Database port (defaults to 3306 if not specified)
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database
```

**With Claude Desktop**

Add this to your `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "mysql": {
      "command": "uv",
      "args": [
        "--directory", 
        "path/to/mysql_mcp_server",
        "run",
        "mysql_mcp_server"
      ],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "your_username",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}
```

**As a standalone server**

```bash
# Install dependencies
pip install -r requirements.txt

# Run the server
python -m mysql_mcp_server
```

**Development**

```bash
# Clone the repository
git clone https://github.com/yourusername/mysql_mcp_server.git
cd mysql_mcp_server

# Create virtual environment
python -m venv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows

# Install development dependencies
pip install -r requirements-dev.txt

# Run tests
pytest
```

## Tools

## Available Tools

1. List available MySQL tables as resources (Allows AI assistants to list tables).
2. Read table contents (Allows AI assistants to read data).
3. Execute SQL queries with proper error handling (Allows AI assistants to execute SQL queries).
4. Secure database access through environment variables (Provides secure database access).
5. Comprehensive logging (Provides comprehensive logging).
