Skip to main content
Glama
mysql-mcp

mysql-mcp

by raviraj-ntp

MySQL MCP

Feature-rich MCP server for MySQL and MariaDB with multi-connection support. Connect many instances at once — query schemas, run scripts, test stored procedures with sandbox rollback.

  • npm: @raviraj87/mysql-mcp

  • Runs locally via stdio (any MCP-compatible client)

  • Supports MySQL 5.7+, 8.x, MariaDB 10.x–11.x, InnoDB/Aria/MyISAM


Quick start

Connect to the MySQL server — no database required in the URI. Use list_databases, then pass database on each tool call (or set default_database in config).

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "@raviraj87/mysql-mcp"],
      "env": {
        "MYSQL_URI": "mysql://user:pass@localhost:3306"
      }
    }
  }
}

Typical workflow

  1. list_databases — discover databases on the server

  2. Pick a database (agent asks, or you pass it explicitly)

  3. list_tables, query, etc. with "database": "myapp"

Optional: set default_database in YAML so tools skip the database param for that connection.

Multiple connections — copy config.example.yaml → ~/.mysql-mcp.yaml:

default_connection: local
connections:
  local:
    uri_env: MYSQL_URI
    default_database: myapp   # optional — omit to choose per tool call
  staging:
    uri_env: MYSQL_URI_STAGING
  prod:
    uri_env: MYSQL_URI_PROD
    read_only: true

Set URIs in MCP env. Every tool accepts optional connection: "staging".

Extra connections via env:

MYSQL_EXTRA_CONNECTIONS=staging:MYSQL_URI_STAGING,prod:MYSQL_URI_PROD

Server vs database

Level

Config

Example

Server

MYSQL_URI host only

mysql://user:pass@host:3306

Default DB

default_database in YAML (optional)

myapp

Per tool

database param

{ "database": "nsm", "table": "users" }

Tools like ping, list_databases, and server_info work without a database. Schema/query tools require database or default_database.


Related MCP server: mcp-server-sqlite

Tools (~55)

Connection: list_connections, ping, server_info, connect

Metadata: list_databases, list_tables, describe_table, show_create_table, list_indexes, list_foreign_keys, table_stats, list_views, list_triggers, list_events

Read: query, query_one, explain, count, sample_rows, distinct_values, export_query

Write: execute, execute_batch, insert_rows, delete_rows, truncate_table

Routines: list_procedures, list_functions, describe_procedure, show_create_procedure, show_create_function, call_procedure, call_function, test_procedure, create_procedure, drop_procedure, routine_overview

Scripts: split_script, validate_script, run_script, test_script, load_script_file, run_script_with_vars

Admin: execute_ddl, create_database, drop_database, create_index, drop_index, show_grants

Diagnostics: processlist, status, variables, innodb_status, replication_status, kill_query, health_check

Composite: explore_table, database_overview, analyze_query, compare_tables, index_health


Stored procedures & scripts

Test a procedure (rollback by default):

{
  "tool": "test_procedure",
  "arguments": {
    "database": "myapp",
    "procedure": "sp_create_order",
    "params": { "p_customer_id": 42, "p_amount": 99.99 },
    "setup_sql": ["INSERT INTO customers (id) VALUES (42)"]
  }
}

Test a SQL script:

{
  "tool": "test_script",
  "arguments": {
    "database": "myapp",
    "script": "DELIMITER $$\nCREATE PROCEDURE ...\nEND$$\nDELIMITER ;\nCALL my_proc(1);"
  }
}

split_script handles DELIMITER changes. Sandbox rollback requires InnoDB/Aria unless compatibility.allow_myisam_sandbox: true.


Safety

  • Global or per-connection read_only

  • max_rows auto-LIMIT on SELECT

  • query_timeout_ms via session max_execution_time / max_statement_time

  • explain_check — reject full table scans

  • confirmation_required_tools — destructive ops need confirmed: true

  • test_sandbox_default: true — scripts/SP tests roll back unless committed

  • allowed_databases per connection

  • Blocks INTO OUTFILE, LOAD DATA, SHUTDOWN


Install from source

cd mysql-mcp
npm install
npm run build
{
  "command": "node",
  "args": ["/path/to/mysql-mcp/dist/index.js"]
}

License

Copyright © 2026 Ravi Raj. Licensed under the MIT License.

Available Tools

61 tools
analyze_queryC

Composite: EXPLAIN with human-readable summary.

Inputs: sql (required), params, database, connection.

call_functionC

Call a stored function with positional params.

Inputs: function (required), params, database, connection.

call_procedureB

Call a stored procedure with JSON params; captures result sets and OUT parameters.

Inputs: procedure (required), params, database, connection.

compare_tablesA

Compare column definitions between two tables (same or different connections).

Inputs: table (required), other_table (required), database, connection, +2 more.

connectC

Add or replace a runtime connection by URI. Use a unique name.

Inputs: name (required), connectionString (required), readOnly, description, +1 more.

countB

COUNT rows in a table with optional WHERE clause.

Inputs: table (required), where, params, database, +1 more.

create_databaseC

Create a database.

Inputs: database (required), charset, collation, confirmed, +1 more.

create_indexC

Create an index on a table.

Inputs: table (required), columns (required), index_name (required), unique, +2 more.

create_procedureC

Deploy a stored procedure from SQL (CREATE PROCEDURE body).

Inputs: sql (required), database, confirmed, connection, +1 more.

database_overviewA

Composite: all tables with row estimates, engine, and sizes.

Inputs: database, connection.

delete_rowsB

DELETE rows with a required WHERE clause.

Inputs: table (required), where (required), params, database, +2 more.

describe_procedureC

Parameter list and metadata for a stored procedure.

Inputs: procedure (required), database, connection.

describe_tableC

Column definitions for a table (information_schema + SHOW FULL COLUMNS).

Inputs: table (required), database, connection.

distinct_valuesC

Distinct values for a column (capped).

Inputs: table (required), column (required), limit, database, +1 more.

drop_databaseC

Drop a database. Requires confirmed=true.

Inputs: database (required), confirmed, connection.

drop_indexC

Drop an index from a table.

Inputs: table (required), index_name (required), database, confirmed, +1 more.

drop_procedureC

Drop a stored procedure.

Inputs: procedure (required), database, confirmed, connection.

executeB

Execute a single DML statement (INSERT/UPDATE/DELETE) with ? placeholders.

Inputs: sql (required), params, database, connection.

execute_batchB

Execute multiple DML statements in a single transaction.

Inputs: statements (required), database, confirmed, connection.

execute_ddlB

Execute a DDL statement (CREATE/ALTER/DROP). Requires confirmed=true.

Inputs: sql (required), database, confirmed, connection.

explainC

EXPLAIN a SELECT query (JSON format when supported).

Inputs: sql (required), params, analyze, database, +1 more.

explore_tableC

Composite: columns, indexes, foreign keys, stats, and sample rows.

Inputs: table (required), database, connection, sampleSize.

export_queryC

Run a SELECT and return truncated JSON for large results.

Inputs: sql (required), params, database, maxChars, +1 more.

health_checkC

Composite health: ping, version, engine, replication snippet.

Inputs: connection.

index_healthB

List indexes with cardinality and flag possible duplicates.

Inputs: table, database, connection.

innodb_statusA

SHOW ENGINE INNODB STATUS (InnoDB only).

Inputs: connection.

insert_rowsA

Bulk insert rows from a JSON array of objects (column keys must match).

Inputs: rows (required), table (required), database, connection.

kill_queryC

Kill a query by connection id.

Inputs: id (required), confirmed, connection.

list_connectionsA

List all configured MySQL/MariaDB connections (names only, no URIs).

Inputs: no named parameters.

list_databasesB

List databases on the server (respects allowed_databases).

Inputs: connection.

list_eventsB

List scheduled events in a database.

Inputs: database, connection.

list_foreign_keysC

List foreign key constraints for a table.

Inputs: table, database, connection.

list_functionsB

List stored functions in a database.

Inputs: database, connection.

list_indexesC

List indexes for a table.

Inputs: table (required), database, connection.

list_proceduresC

List stored procedures in a database.

Inputs: database, connection.

list_tablesC

List tables and views in a database.

Inputs: engine, database, connection.

list_triggersB

List triggers in a database.

Inputs: table, database, connection.

list_viewsC

List views in a database.

Inputs: database, connection.

load_script_fileB

Read a SQL file from disk and optionally execute it (sandbox by default).

Inputs: path (required), execute, sandbox, database, +2 more.

pingB

Ping a MySQL/MariaDB connection (SELECT 1).

Inputs: connection.

processlistB

SHOW FULL PROCESSLIST — active connections and queries.

Inputs: connection.

queryC

Run a parameterized SELECT query. Use ? placeholders for params.

Inputs: sql (required), limit, params, database, +1 more.

query_oneC

Run a SELECT and return the first row only.

Inputs: sql (required), params, database, connection.

replication_statusC

Replication status (SHOW REPLICA/SLAVE STATUS).

Inputs: connection.

routine_overviewA

List all procedures and functions with parameter summaries.

Inputs: database, connection.

run_scriptC

Execute a multi-statement SQL script. Use confirmed=true to commit writes.

Inputs: script (required), sandbox, database, confirmed, +2 more.

run_script_with_varsC

Prepend SET @var statements then run a script.

Inputs: script (required), variables (required), sandbox, database, +1 more.

sample_rowsC

Sample rows from a table.

Inputs: table (required), limit, where, params, +2 more.

server_infoB

Server version, vendor, capabilities, and host metadata.

Inputs: connection.

show_create_functionC

Return CREATE FUNCTION DDL.

Inputs: function (required), database, connection.

show_create_procedureC

Return CREATE PROCEDURE DDL.

Inputs: procedure (required), database, connection.

show_create_tableC

Return CREATE TABLE DDL.

Inputs: table (required), database, connection.

show_grantsB

Show grants for the current user.

Inputs: connection.

split_scriptA

Parse a SQL script into individual statements (DELIMITER-aware). Does not execute.

Inputs: script (required), delimiter.

statusC

Key global status variables.

Inputs: pattern, connection.

table_statsC

Table size and row estimates from information_schema.

Inputs: table (required), database, connection.

test_procedureA

Test a stored procedure in a sandbox transaction (ROLLBACK by default).

Inputs: procedure (required), params, sandbox, database, +5 more.

test_scriptB

Execute a script inside a sandbox transaction (ROLLBACK by default).

Inputs: script (required), sandbox, database, delimiter, +1 more.

truncate_tableC

TRUNCATE a table (requires confirmed=true).

Inputs: table (required), database, confirmed, connection.

validate_scriptC

Parse and classify script statements without executing.

Inputs: script (required), delimiter.

variablesC

Server system variables.

Inputs: pattern, connection.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3/5.0

    Scored across 61 tools

    Disambiguation4/5

    Most tools have clear, distinct purposes, but a few overlap (e.g., analyze_query and explain both explain queries; describe_table and explore_table have overlapping functionality). This could cause some misselection.

    Naming Consistency5/5

    All tools use lowercase snake_case with a consistent verb_noun pattern (e.g., create_database, list_tables). Even single-word names like ping and count are stylistically aligned.

    Tool Count2/5

    With 61 tools, the surface is very large. While comprehensive, it exceeds the typical well-scoped range of 3-15 tools, making it unwieldy for an agent to navigate efficiently.

    Completeness4/5

    The tool set covers almost all common MySQL operations: CRUD for objects, querying, scripting, procedures, replication, health checks, and schema inspection. Minor gaps exist (e.g., user management) but do not significantly hinder typical workflows.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      An MCP server for MySQL that enables users to execute SQL queries, inspect table structures, and explore database schemas through a clean, SOLID-based architecture. It includes built-in security validations to protect against dangerous operations and ensure safe interaction with database resources.
      2
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server for managing multiple MySQL and MariaDB database connections simultaneously, allowing users to run SQL queries and manage schemas through AI-powered tools. It features dynamic connection management, persistent configuration, and granular tools for database, table, and index operations.
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      A multi-database MCP server supporting MySQL, PostgreSQL, MongoDB, and SQLite with read-only and read-write query capabilities, schema inspection, and SSH tunneling, all without Docker.
      5
      57 PyPI
      1
      MIT