Skip to main content
Glama

MySQL MCP Server

by SuMiaoALi

MySQL MCP Server

A Model Context Protocol (MCP) server that provides secure MySQL database operations for AI assistants and other MCP clients.

Features

🛠️ Tools

  • execute_query - Execute safe SQL queries (SELECT, INSERT, SHOW, DESCRIBE)
  • get_table_info - Get detailed table structure information
  • insert_data - Convenient data insertion with automatic parameterization
  • list_tables - List all tables in the database

📊 Resources

  • Database Info (mysql://database/info) - Database metadata and table list
  • Table Structure (mysql://table/{table_name}) - Detailed table schema information

🔒 Security Features

  • Limited Operations: Only allows safe operations (SELECT, INSERT, SHOW, DESCRIBE)
  • SQL Injection Protection: Uses parameterized queries
  • Automatic LIMIT: Adds LIMIT clauses to SELECT queries to prevent large data dumps
  • Connection Pooling: Efficient database connection management

Installation

npm install mysql-mcp-server

Configuration

The server can be configured using environment variables:

VariableDefaultDescription
MYSQL_HOSTlocalhostMySQL server hostname
MYSQL_PORT3306MySQL server port
MYSQL_USERrootMySQL username
MYSQL_PASSWORD(empty)MySQL password
MYSQL_DBmysqlDefault database name
MYSQL_TIMEZONE+00:00MySQL timezone

Usage with MCP Clients

Claude Desktop

Add to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%/Claude/claude_desktop_config.json

{ "mcpServers": { "mysql": { "command": "npx", "args": ["mysql-mcp-server"], "env": { "MYSQL_HOST": "your-mysql-host", "MYSQL_PORT": "3306", "MYSQL_USER": "your-username", "MYSQL_PASSWORD": "your-password", "MYSQL_DB": "your-database" } } } }

Other MCP Clients

For other MCP clients, use the server with stdio transport:

npx mysql-mcp-server

Development

Prerequisites

  • Node.js 18+
  • TypeScript
  • Access to a MySQL database

Setup

  1. Clone the repository:
git clone https://github.com/your-username/mysql-mcp-server.git cd mysql-mcp-server
  1. Install dependencies:
npm install
  1. Set up environment variables:
cp .env.example .env # Edit .env with your database configuration
  1. Build the server:
npm run build

Development Commands

# Build the server npm run build # Watch mode for development npm run watch # Debug with MCP Inspector npm run inspector

Testing

You can test the server using the MCP Inspector:

npm run inspector

This will start the inspector and provide a URL to test the server in your browser.

Example Usage

Once connected through an MCP client, you can:

  1. List all tables:
    Use the list_tables tool
  2. Get table structure:
    Use get_table_info with table_name: "users"
  3. Query data:
    Use execute_query with sql: "SELECT * FROM users LIMIT 10"
  4. Insert data:
    Use insert_data with table_name: "users" and data: {"name": "John", "email": "john@example.com"}

Security Considerations

This server is designed with security in mind:

  • Read-mostly operations: Only SELECT, INSERT, SHOW, and DESCRIBE operations are allowed
  • No destructive operations: UPDATE and DELETE are explicitly forbidden
  • Parameterized queries: All user inputs are properly escaped
  • Connection limits: Uses connection pooling to prevent resource exhaustion
  • Query limits: Automatic LIMIT clauses prevent large data dumps

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details.

-
security - not tested
A
license - permissive license
-
quality - not tested

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Provides secure access to MySQL databases for AI assistants, enabling safe SQL queries, table information retrieval, and data insertion with built-in security protections.

  1. Features
    1. 🛠️ Tools
    2. 📊 Resources
    3. 🔒 Security Features
  2. Installation
    1. Configuration
      1. Usage with MCP Clients
        1. Claude Desktop
        2. Other MCP Clients
      2. Development
        1. Prerequisites
        2. Setup
        3. Development Commands
        4. Testing
      3. Example Usage
        1. Security Considerations
          1. Contributing
            1. License
              1. Related

                Related MCP Servers

                • A
                  security
                  F
                  license
                  A
                  quality
                  Enables AI models to perform MySQL database operations through a standardized interface, supporting secure connections, query execution, and comprehensive schema management.
                  Last updated -
                  7
                  35
                  26
                  JavaScript
                • A
                  security
                  A
                  license
                  A
                  quality
                  Connect and interact with MySQL databases seamlessly. Execute SQL queries, manage database connections, and retrieve data directly through AI assistants. Enhance your AI capabilities with structured access to your MySQL data.
                  Last updated -
                  9
                  4
                  15
                  TypeScript
                  MIT License
                • -
                  security
                  F
                  license
                  -
                  quality
                  Enables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.
                  Last updated -
                  Python
                  • Linux
                  • Apple
                • -
                  security
                  F
                  license
                  -
                  quality
                  A powerful server that enables AI agents to interact with MySQL databases, execute SQL queries, and manage database content through a simple interface.
                  Last updated -
                  22
                  5
                  JavaScript
                  • Apple

                View all related MCP servers

                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/SuMiaoALi/mysql-mcp-server'

                If you have feedback or need assistance with the MCP directory API, please join our Discord server