Featured

Deploy OpenClaw in 60 seconds — 20% off logoDeploy OpenClaw in 60 seconds — 20% off

Launch OpenClaw on Hostinger in about 60 seconds and keep your agent live 24/7. Our referral link gives you 20% off, no coupon code needed.

Launch on Hostinger
Run your Hermes agent on Hostinger, fully managed logoRun your Hermes agent on Hostinger, fully managed

Launch Hermes on Hostinger in one click, fully managed, no VPS knowledge needed. Use code ZACAARON10 for 10% off.

Launch on Hostinger
Crawl and scrape any site into clean data, 10% off logoCrawl and scrape any site into clean data, 10% off

Firecrawl crawls and scrapes any site into clean markdown for your agent. Get 1,000 free credits, and new users get 10% off their first purchase.

Try Firecrawl free
6,000+ web scrapers for your AI agent, start free logo6,000+ web scrapers for your AI agent, start free

Apify gives your agent live web data: 6,000+ prebuilt scrapers and actors, MCP-ready. Sign up free with $5 in usage credits.

Try Apify free
One API to scrape, enrich, and extract the internet. logoOne API to scrape, enrich, and extract the internet.

Context.dev gives your agents a single API to scrape, enrich, and extract live web data — no proxies, no parsers, no maintenance.

Start building free
SetupClaw: done-for-you OpenClaw for founders & exec teams logoSetupClaw: done-for-you OpenClaw for founders & exec teams

White-glove OpenClaw for founders and exec teams (4–50+ employees): we install, harden, integrate your tools, and maintain it — secured from day one.

Get it set up for you
SEO data APIs for your agent, $1 free credit logoSEO data APIs for your agent, $1 free credit

DataForSEO gives your agent live access to SERP results, keyword data, backlinks, and on-page SEO data through one API. New accounts get a $1 credit, good for up to 20,000 keyword or backlink lookups.

Try DataForSEO free
Reach 48,000+ AI builders

A flat monthly placement in front of developers actively installing AI tools. No lock-in, cancel anytime.

Advertise here

Works with

Claude CodeClaude DesktopCursorVS CodeClineCodex CLIOpenClaw+ any MCP client

Install to Claude Code

This server doesn't publish a one-line install command. Follow the setup in the source repository.

Summary

Enables AI models to interact with MySQL databases through MCP protocol, supporting queries, table schema inspection, and data manipulation operations.

README.md

MySQL MCP 工具

针对MySQL数据库操作的MCP(Model Context Protocol)工具实现,为AI模型提供数据库操作能力。

  • 推荐使用本地模型使用这个工具,防止出现不必要的数据泄露风险

功能特性

  • MySQL数据库连接管理
  • 表结构查询
  • 数据增删改查操作
  • 错误处理和连接状态管理
  • MCP协议支持,可与AI模型集成

安装

npm install

使用方法

作为MCP服务器

将以下配置添加到你的MCP客户端配置文件中:

{
  "mcpServers": {
    "mysql-mcp-tool": {
      "command": "npx",
      "args": ["mysql-mcp-tool", "server"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "",
        "MYSQL_DATABASE": "test"
      }
    }
  }
}

命令行使用

# 查询表
mysql-mcp-tool tables

# 查看表结构
mysql-mcp-tool schema users

# 执行SQL
mysql-mcp-tool query "SELECT * FROM users WHERE id = ?" -p '["1"]'

# 启动MCP服务器
mysql-mcp-tool server -h localhost -u root -p password -d mydb

编程使用

import MySQLMCPTool from './index.js';

const tool = new MySQLMCPTool({
  host: 'localhost',
  user: 'root',
  password: '',
  database: 'test'
});

await tool.connect();
const result = await tool.select('users', { id: 1 });
await tool.disconnect();

API文档

基础方法

  • connect() - 连接数据库
  • disconnect() - 断开连接
  • executeQuery(sql, params) - 执行SQL查询

数据操作

  • getTables() - 获取所有表
  • getTableSchema(tableName) - 获取表结构
  • select(tableName, where, limit) - 查询数据
  • insert(tableName, data) - 插入数据
  • update(tableName, data, where) - 更新数据
  • delete(tableName, where) - 删除数据

MCP工具

该工具提供以下MCP工具:

  1. mysql_query - 执行MySQL查询
  • 参数:sql(必需),params(可选)
  1. mysql_tables - 获取所有表
  • 参数:无
  1. mysql_schema - 获取表结构
  • 参数:table(必需)
  1. mysql_insert - ⚠️ 警告:插入数据 - 使用者自负责任
  • 参数:table(必需),data(必需)
  1. mysql_update - ⚠️ 警告:更新数据 - 使用者自负责任
  • 参数:table(必需),data(必需),where(可选)
  1. mysql_delete - ⚠️ 警告:删除数据 - 使用者自负责任
  • 参数:table(必需),where(可选)

开发

# 安装依赖
npm install

# 运行测试
npm test

# 启动开发模式
npm start

依赖

  • mysql2: MySQL数据库驱动
  • commander: 命令行参数解析
  • Node.js ES模块支持

许可证

MIT

See related servers & alternatives →

Related MCP servers

Browse all →

Related guides

Hand-picked reading to help you choose and use Databases servers.