Get the FREE Ultimate OpenClaw Setup Guide →

mcp -mysql

MCP Tool server application with MySQL DDL operations, permission control and operation logs, supports npx/global commands.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio liliangshan-mcp-server-mysql npx @liangshanli/mcp-server-mysql \
  --env READONLY="false" \
  --env ALLOW_DDL="true" \
  --env ALLOW_DROP="false" \
  --env MYSQL_HOST="localhost" \
  --env MYSQL_PORT="3306" \
  --env MYSQL_USER="root" \
  --env TOOL_PREFIX="projA" \
  --env ALLOW_DELETE="false" \
  --env PROJECT_NAME="MyProject" \
  --env MYSQL_DATABASE="your_database" \
  --env MYSQL_PASSWORD="your_password"

How to use

This MCP server provides a MySQL-compatible interface with DDL support, permission controls, and operation logging. It exposes tools for executing SQL queries (sql_query), retrieving database information (get_database_info), accessing operation logs (get_operation_logs), and accessing DDL-related logs (get_ddl_sql_logs in v2.0.1+). You can run the server via npx or install it locally and start it with npm. To perform actions, send JSON-RPC requests to the server’s standard input/output stream after startup, using the tool names defined in the configuration (e.g., sql_query, get_database_info, get_operation_logs, get_ddl_sql_logs, check_permissions). When running multiple instances, each instance can use a different TOOL_PREFIX to isolate tools and logs.

How to install

Prerequisites:

  • Node.js and npm installed
  • Git installed (for source installation)
  1. Global installation (recommended):
npm install -g @liangshanli/mcp-server-mysql
  1. Local installation:
npm install @liangshanli/mcp-server-mysql
  1. From source:
git clone https://github.com/liliangshan/mcp-server-mysql.git
cd mcp-server-mysql
npm install
  1. Configure environment variables (example):
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=root
export MYSQL_PASSWORD=your_password
export MYSQL_DATABASE=your_database
export READONLY=false
export ALLOW_DDL=true
export ALLOW_DROP=false
export ALLOW_DELETE=false
export TOOL_PREFIX="projA"            # optional
export PROJECT_NAME="MyProject"        # optional
  1. Start the server:
  • Direct Run (if installed globally):
mcp-server-mysql
  • Using npm scripts (local installation):
npm start
  • Managed start (production):
npm run start-managed

Note: You can also run via npx without installation:

npx @liangshanli/mcp-server-mysql

Additional notes

Tips:

  • Use TOOL_PREFIX to isolate tools and configuration when running multiple MySQL server instances. Each instance will have its own logs and DDL files (e.g., ./.setting.projA/).
  • Enable READONLY to restrict commands to SELECT and SHOW for safety in production environments.
  • The DDL logging (get_ddl_sql_logs) is available from v2.0.1+ and records only successful DDL operations with timestamps.
  • If you enable DDL-related permissions, ensure ALLOW_DDL and related flags align with your security policy.
  • For editor integration, you can define multiple MCP servers with different TOOL_PREFIX values to manage multiple databases concurrently.
  • Ensure your environment variables are securely stored and not committed to source control.
  • When using multiple instances, commands will be prefixed accordingly (e.g., local_sql_query vs online_sql_query) to avoid conflicts.

Related MCP Servers

Sponsor this space

Reach thousands of developers