Get the FREE Ultimate OpenClaw Setup Guide →

mysql

A general Mysql-MCP-Server

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio sumiaoali-mysql-mcp-server npx mysql-mcp-server \
  --env MYSQL_DB="your-database" \
  --env MYSQL_HOST="your-mysql-host" \
  --env MYSQL_PORT="3306" \
  --env MYSQL_USER="your-username" \
  --env MYSQL_PASSWORD="your-password" \
  --env MYSQL_TIMEZONE="+00:00"

How to use

This MCP server provides secure MySQL database operations for AI assistants and other MCP clients. It exposes safe tooling to query and inspect a MySQL database, including listing tables, retrieving table structures, executing parameterized queries, and inserting data with automatic parameterization. Core features include limiting dangerous operations, automatic query limiting to prevent large data dumps, and connection pooling for efficient resource use. Clients connect via the MCP protocol and can use the included tools to inspect database metadata and to perform routine data operations in a controlled, safe manner. The available tools are: list_tables to enumerate all tables in the connected database, get_table_info to fetch detailed schema information for a table, execute_query to run safe SELECT/INSERT/SHOW/DESCRIBE statements with parameterization, and insert_data to insert rows with automatic parameter handling.

How to install

Prerequisites:

  • Node.js 18+ installed on the machine
  • A MySQL database accessible from where the MCP server will run

Installation steps:

  1. Install the MCP server package globally or in your project: npm install mysql-mcp-server

  2. Set up environment variables for your MySQL connection (example shown for Claude Desktop usage):

    • MYSQL_HOST=your-mysql-host
    • MYSQL_PORT=3306
    • MYSQL_USER=your-username
    • MYSQL_PASSWORD=your-password
    • MYSQL_DB=your-database
    • MYSQL_TIMEZONE=+00:00
  3. Start the server (via npx in MCP usage): npx mysql-mcp-server

  4. If building or developing locally, clone the repository, install dependencies, and run development scripts as described in the repository’s development section.

Optional: Create a .env file with the above variables and ensure your environment loads them before starting the server.

Additional notes

Tips and considerations:

  • Security: The server restricts operations to SELECT, INSERT, SHOW, and DESCRIBE, and uses parameterized queries to prevent SQL injection. UPDATE and DELETE are not permitted.
  • Auto LIMIT: Queries receiving large result sets are automatically limited to prevent heavy data dumps.
  • Connection pooling helps manage resources under concurrent access.
  • If you encounter connection errors, verify that MYSQL_HOST, MYSQL_USER, and MYSQL_PASSWORD are correct and that the user has access to the specified database.
  • For MCP client configuration, ensure the client is set to use the stdio transport or the appropriate transport supported by your environment.
  • If you need to adjust time zone handling, modify MYSQL_TIMEZONE accordingly to match your MySQL server settings.

Related MCP Servers

Sponsor this space

Reach thousands of developers