MCP Server MySQL
This MCP server enables LLMs to interact with MySQL databases through a standardized protocol, supporting read-only queries, data modification, and full schema/database administration.
Database Management
List, create, drop, and switch databases (with optional charset/collation settings)
Table Operations
List, describe, create, alter (add/drop/modify/rename columns), and drop tables
Data Querying & Modification
Execute
SELECTqueries with parameterized prepared statement supportExecute
INSERT,UPDATE,DELETEstatements (when write mode is enabled)Dry-run modifying statements inside a rolled-back transaction to preview effects safely
Schema Inspection
Inspect tables, columns, and indexes for AI context (
inspect_schema)Find tables by name and sample rows
Run
EXPLAINon SELECT queries for query analysis
Index Management
Create and drop indexes (including unique indexes)
Connection & Health
Connect to a database at runtime with explicit credentials
Health check to verify connection and retrieve server status
Safety & Permission Controls
Defaults to read-only mode; write and DDL operations must be explicitly enabled via environment variables (
MYSQL_MODE,MYSQL_ALLOW_DDL,MYSQL_ALLOW_INSERT,MYSQL_ALLOW_UPDATE,MYSQL_ALLOW_DELETE)High-risk operations (
alter_table,drop_table,drop_database,drop_index) require aconfirmparameter matching the target nameQuery results can be capped with
MYSQL_MAX_ROWSto prevent large data dumps
Provides comprehensive MySQL database operations including database and table management, data querying and modification (SELECT, INSERT, UPDATE, DELETE), index management, and schema operations with configurable permission controls for write operations.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Server MySQL show me the first 10 rows from the users table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Server MySQL
A Model Context Protocol (MCP) server that provides MySQL database operations. This server enables LLMs to interact with MySQL databases through a standardized protocol.
Features
Database Management: Create, drop, list, and switch databases
Table Operations: Create, alter, drop, describe, and list tables
Data Queries: Execute SELECT queries and retrieve results
Data Modification: Execute INSERT, UPDATE, DELETE statements
Index Management: Create and drop indexes
Related MCP server: MySQL MCP Server
Installation
npm install
npm run buildConfiguration
Set environment variables for database connection:
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=root
export MYSQL_PASSWORD=your-password
export MYSQL_DATABASE=your-database # optionalSafety and Permission Controls
The server defaults to read-only mode. Enable write or schema operations explicitly:
export MYSQL_MODE=readonly # readonly | data-write | schema-write | admin
export MYSQL_ALLOW_DDL=false # Set to "true" to enable schema/admin tools
export MYSQL_MAX_ROWS=100 # Optional cap for query result rowsLegacy data-write controls are still supported and are enforced when MYSQL_MODE
allows data writes:
export MYSQL_ALLOW_INSERT=true # Set to "false" to disable INSERT
export MYSQL_ALLOW_UPDATE=true # Set to "false" to disable UPDATE
export MYSQL_ALLOW_DELETE=false # Set to "false" to disable DELETEOr use the connect tool at runtime to specify connection parameters.
High-risk DDL tools require a confirm parameter that matches the target name:
alter_table:confirmmust match the table namedrop_table:confirmmust match the table namedrop_database:confirmmust match the database namedrop_index:confirmmust match the index name
For AI-assisted development, prefer least-privilege MySQL users. Use a read-only
database account for exploration and enable MYSQL_MODE=data-write,
MYSQL_MODE=schema-write, or MYSQL_MODE=admin only for trusted workflows.
Supported AI Applications
This MCP server can be used with any application that supports the Model Context Protocol (MCP):
Claude Desktop - Anthropic's official desktop application
Claude Code - Anthropic's official CLI tool for developers
Cline - AI coding assistant VS Code extension
Zed - High-performance code editor with built-in AI
Any MCP-compatible application - MCP is an open protocol developed by Anthropic
Usage with Claude Desktop
Using npx (Recommended)
Add to your claude_desktop_config.json:
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@nilsir/mcp-server-mysql"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "your-password",
"MYSQL_DATABASE": "your-database",
"MYSQL_MODE": "readonly",
"MYSQL_ALLOW_DDL": "false",
"MYSQL_ALLOW_INSERT": "true",
"MYSQL_ALLOW_UPDATE": "true",
"MYSQL_ALLOW_DELETE": "false",
"MYSQL_MAX_ROWS": "100"
}
}
}
}Using Local Installation
{
"mcpServers": {
"mysql": {
"command": "node",
"args": ["/absolute/path/to/mcp-server-mysql/dist/index.js"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "your-password",
"MYSQL_DATABASE": "your-database",
"MYSQL_MODE": "readonly",
"MYSQL_ALLOW_DDL": "false",
"MYSQL_ALLOW_INSERT": "true",
"MYSQL_ALLOW_UPDATE": "true",
"MYSQL_ALLOW_DELETE": "false",
"MYSQL_MAX_ROWS": "100"
}
}
}
}Available Tools
Tool | Description |
| Connect to a MySQL database |
| Execute SELECT queries |
| Run EXPLAIN for a single SELECT query |
| Execute INSERT/UPDATE/DELETE queries when policy allows |
| Execute INSERT/UPDATE/DELETE in a transaction and roll it back |
| List all databases |
| List tables in a database |
| Get table structure |
| Inspect tables, columns, and indexes for AI context |
| Find tables by table or column name |
| Read a capped sample of rows from a table |
| Create a new table |
| Modify table structure |
| Drop a table |
| Create a new database |
| Drop a database |
| Switch to a database |
| Create an index |
| Drop an index |
Examples
Query data
Use the query tool with sql: "SELECT * FROM users WHERE active = ?"
and params: [true]Analyze a SELECT query plan
Use the explain_query tool with:
- sql: "SELECT * FROM users WHERE email = ?"
- params: ["user@example.com"]
- format: "traditional"explain_query only accepts one SELECT statement. Use format: "json" when an
AI-readable JSON plan is more useful.
Create a table
Use the create_table tool with:
- table: "users"
- columns: [
{"name": "id", "type": "INT", "primaryKey": true, "autoIncrement": true},
{"name": "email", "type": "VARCHAR(255)", "nullable": false},
{"name": "created_at", "type": "TIMESTAMP", "default": "CURRENT_TIMESTAMP"}
]Inspect schema for AI context
Use the inspect_schema tool with:
- database: "nilsir"
- includeColumns: true
- includeIndexes: trueFind likely tables or columns
Use the find_tables tool with:
- database: "nilsir"
- term: "user"Sample rows safely
Use the sample_rows tool with:
- database: "nilsir"
- table: "users"
- limit: 5Sampling is read-only and capped at 50 rows.
Insert data
Use the execute tool with sql: "INSERT INTO users (email) VALUES (?)"
and params: ["user@example.com"]Requires MYSQL_MODE=data-write or higher.
Dry-run a data change
Use the dry_run_execute tool with sql: "UPDATE users SET active = ? WHERE id = ?"
and params: [false, 123]The statement runs inside a transaction and is rolled back before returning.
Drop a table
Use the drop_table tool with:
- table: "users"
- confirm: "users"Requires MYSQL_MODE=schema-write or MYSQL_MODE=admin and
MYSQL_ALLOW_DDL=true.
Development
npm install
npm run build
npm testIntegration coverage for dry-run rollback is opt-in because it needs a real test database:
MYSQL_INTEGRATION_TEST=true npm testLicense
MIT
Available Tools
15 toolsalter_tableC
Modify an existing table structure
Inputs: table (required), operation (required), column (required), definition, +2 more.
connectA
Connect to a MySQL database. If not called explicitly, will use environment variables for connection.
Inputs: host, port, user, password, +1 more.
create_databaseC
Create a new database
Inputs: database (required), charset, collation.
create_indexC
Create an index on a table
Inputs: table (required), indexName (required), columns (required), unique, +1 more.
create_tableC
Create a new table with specified columns
Inputs: table (required), columns (required), database.
describe_tableC
Get the structure/schema of a table
Inputs: table (required), database.
drop_databaseC
Drop/delete a database
Inputs: database (required).
drop_indexC
Drop an index from a table
Inputs: table (required), indexName (required), database.
drop_tableC
Drop/delete a table
Inputs: table (required), database.
executeB
Execute an INSERT, UPDATE, DELETE or other modifying query. Returns affected rows count.
Inputs: sql (required), params.
health_checkB
Check database connection health and get server status
Inputs: no named parameters.
list_databasesB
List all databases on the MySQL server
Inputs: no named parameters.
list_tablesB
List all tables in the current or specified database
Inputs: database.
queryB
Execute a SELECT query and return results. Use this for reading data.
Inputs: sql (required), params.
use_databaseC
Switch to a different database
Inputs: database (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 15 tools
Every tool has a clearly distinct purpose with no ambiguity. Each tool targets a specific database operation (e.g., create_table vs. alter_table, query vs. execute) with clear boundaries between read operations, write operations, and administrative tasks.
Tool names follow a consistent verb_noun pattern throughout (e.g., create_database, list_tables, drop_index). All names use snake_case with descriptive verbs that clearly indicate the action being performed.
15 tools is well-scoped for a MySQL database server, covering essential CRUD operations, schema management, and administrative functions. Each tool earns its place without redundancy or bloat.
The toolset provides complete coverage for MySQL database operations including connection management, database/table lifecycle (create, describe, drop), data manipulation (query, execute), indexing, and administrative functions. No obvious gaps exist for core database workflows.
Maintenance
Related MCP Connectors
PostgreSQL, MySQL, OpenAPI/Swagger, and shared Agent Memory with scoped access.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Guard AI agents' PostgreSQL/MySQL access via MCP: SQL audit, auth, masking, write approval
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables AI models to perform MySQL database operations through a standardized interface, supporting secure connections, query execution, and comprehensive schema management.781 npm33MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to securely connect to and manage MySQL databases with support for multiple database connections, complete CRUD operations, schema inspection, and dynamic connection management through natural language.31 npm81MIT
- AlicenseNot gradedqualityNot gradedmaintenanceEnables AI assistants to securely interact with MySQL databases through tools for query execution, schema inspection, and transaction management. It features built-in safety controls like row limits and query validation to ensure safe and standardized database access.896 npm-
- AlicenseNot gradedqualityDmaintenanceEnables AI models to interact with MySQL databases through MCP protocol, supporting queries, table schema inspection, and data manipulation operations.47 npmMIT