MySQL MCP Server
MySQL MCP 服务器
这是一个模型上下文协议 (MCP) 服务器,提供对 MySQL 数据库的访问。它允许代理针对 MySQL 数据库执行 SQL 查询。
特征
对 MySQL 数据库执行 SQL 查询:
读取数据(SELECT 语句)
创建表(CREATE TABLE 语句)
插入数据(INSERT INTO 语句)
更新数据(UPDATE 语句)
删除数据(DELETE FROM 语句)
以 JSON 格式返回查询结果
可配置数据库连接设置
使用唯一 ID 进行事务日志记录
Related MCP server: MCP MySQL Server
先决条件
Node.js(v14 或更高版本)
MySQL 服务器
MCP SDK
安装
克隆或下载此存储库
安装依赖项:
cd mysql-mcp-server
npm install构建服务器:
npm run build配置
MySQL MCP 服务器使用以下环境变量进行配置:
MYSQL_HOST:MySQL 服务器主机名(默认值:'localhost')MYSQL_PORT:MySQL 服务器端口(默认值:3306)MYSQL_USER:MySQL 用户名(默认值:'mcp101')MYSQL_PASSWORD:MySQL 密码(默认值:'123qwe')MYSQL_DATABASE:MySQL 数据库名称(默认值:'mcpdb')
数据库设置
创建 MySQL 数据库:
CREATE DATABASE mcpdb;创建具有数据库访问权限的 MySQL 用户:
CREATE USER 'mcp101'@'localhost' IDENTIFIED BY '123qwe';
GRANT ALL PRIVILEGES ON mcpdb.* TO 'mcp101'@'localhost';
FLUSH PRIVILEGES;使用示例数据创建测试表:
USE mcpdb;
CREATE TABLE test_users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO test_users (name, email) VALUES
('John Doe', 'john@example.com'),
('Jane Smith', 'jane@example.com'),
('Bob Johnson', 'bob@example.com');MCP 配置
将 MySQL MCP 服务器添加到您的 MCP 设置文件:
VSCode(Claude扩展)
文件: ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
根据您的 MySQL 配置更改参数
{
"mcpServers": {
"mysql-mcp-server": {
"autoApprove": [],
"disabled": false,
"timeout": 60,
"command": "node",
"args": [
"/path/to/mysql-mcp-server/build/index.js"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "mcp101",
"MYSQL_PASSWORD": "123qwe",
"MYSQL_DATABASE": "mcpdb"
},
"transportType": "stdio"
}
}
}克劳德桌面应用程序
文件: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"mysql-mcp-server": {
"autoApprove": [],
"disabled": false,
"timeout": 60,
"command": "node",
"args": [
"/path/to/mysql-mcp-server/build/index.js"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "mcp101",
"MYSQL_PASSWORD": "123qwe",
"MYSQL_DATABASE": "mcpdb"
},
"transportType": "stdio"
}
}
}用法
配置完成后,您就可以使用 MySQL MCP 服务器与 Claude 进行对话。例如:
“您能向我显示 test_users 表中的所有用户吗?”
Claude将使用run_sql_query工具执行:
SELECT * FROM test_users可用工具
运行sql查询
对 MySQL 数据库执行只读 SQL 查询(仅限 SELECT 语句)。
参数:
query:要执行的 SQL SELECT 查询。
例子:
{
"query": "SELECT * FROM test_users"
}创建表
在 MySQL 数据库中创建一个新表。
参数:
query:要执行的 SQL CREATE TABLE 查询。
例子:
{
"query": "CREATE TABLE products (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), price DECIMAL(10,2))"
}插入数据
将数据插入 MySQL 数据库的表中。
参数:
query:要执行的 SQL INSERT INTO 查询。
例子:
{
"query": "INSERT INTO products (name, price) VALUES ('Laptop', 999.99), ('Smartphone', 499.99)"
}更新数据
更新 MySQL 数据库中的表中的数据。
参数:
query:要执行的 SQL UPDATE 查询。
例子:
{
"query": "UPDATE products SET price = 899.99 WHERE name = 'Laptop'"
}删除数据
从 MySQL 数据库的表中删除数据。
参数:
query:要执行的 SQL DELETE FROM 查询。
例子:
{
"query": "DELETE FROM products WHERE name = 'Smartphone'"
}安全注意事项
使用具有适当权限的专用 MySQL 用户来管理 MCP 服务器
如果只需要查询数据,请考虑使用只读权限
安全地存储数据库凭证等敏感信息
所有操作均以唯一的事务 ID 记录,以供审计
Available Tools
6 toolscreate_tableC
Creates a new table in the MySQL database.
Inputs: query (required).
delete_dataC
Deletes data from a table in the MySQL database.
Inputs: query (required).
execute_sqlB
Executes any non-SELECT SQL statement (e.g., ALTER TABLE, DROP, etc.)
Inputs: query (required).
insert_dataC
Inserts data into a table in the MySQL database.
Inputs: query (required).
run_sql_queryA
Executes a read-only SQL query (SELECT statements only) against the MySQL database.
Inputs: query (required).
update_dataC
Updates data in a table in the MySQL database.
Inputs: query (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Most tools have distinct purposes with clear boundaries (e.g., create_table vs. insert_data vs. update_data). However, execute_sql and run_sql_query could cause confusion since both execute SQL statements, differentiated only by read-only vs. non-SELECT operations, which might not be immediately obvious to an agent.
All tool names follow a consistent verb_noun pattern (e.g., create_table, delete_data, execute_sql), with no mixing of conventions. This predictability makes it easy for agents to understand and use the tool set.
With 6 tools, this server is well-scoped for basic MySQL database operations. Each tool serves a clear purpose (e.g., table creation, data manipulation, query execution), and the count is appropriate for covering core functionalities without being overwhelming.
The tool set provides good coverage for basic CRUD operations (create, read, update, delete) and table management. However, there are minor gaps, such as missing tools for listing tables or databases, which could limit agents in exploratory tasks, though core workflows are still supported.
Related MCP Connectors
Hosted MySQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
The Mercado Pago MCP Server implements the Model Context Protocol to provide AI agents and LLMs with access to Mercado Pago's APIs and tools within compatible development environments. It acts as an intermediary that translates Mercado Pago resources into executable functions (tools) that AI applications can invoke to perform actions and automate flows. The server simplifies integration, enables using documentation to implement or improve code, and optimizes operations through natural language interactions without manual implementations.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Hosted SQL Server MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables AI models to interact with MySQL databases, providing tools for querying, executing statements, listing tables, and describing table structures.5329 npmMIT
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables AI models to interact with MySQL databases through a standardized interface, providing tools for querying, executing commands, and managing database schemas.7MIT
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables AI models to interact with MySQL databases through natural language, supporting SQL queries, table creation, and schema exploration.3-
- AlicenseBqualityDmaintenanceA server based on Model Context Protocol that enables AI models to interact with MySQL databases through a standardized interface, supporting features like query execution, table listing, and automated connection management.422 npm10MIT