Skip to main content
Glama

MySQL MCP Server

by michael7736

MySQL MCP Server

This is a Model Context Protocol (MCP) server that provides access to a MySQL database. It allows agent to execute SQL queries against a MySQL database.

Features

  • Execute SQL queries against a MySQL database:
    • Read data (SELECT statements)
    • Create tables (CREATE TABLE statements)
    • Insert data (INSERT INTO statements)
    • Update data (UPDATE statements)
    • Delete data (DELETE FROM statements)
  • Returns query results in JSON format
  • Configurable database connection settings
  • Transaction logging with unique IDs

Prerequisites

  • Node.js (v14 or higher)
  • MySQL server
  • MCP SDK

Installation

  1. Clone or download this repository
  2. Install dependencies:
cd mysql-mcp-server npm install
  1. Build the server:
npm run build

Configuration

The MySQL MCP server uses the following environment variables for configuration:

  • MYSQL_HOST: MySQL server hostname (default: 'localhost')
  • MYSQL_PORT: MySQL server port (default: 3306)
  • MYSQL_USER: MySQL username (default: 'mcp101')
  • MYSQL_PASSWORD: MySQL password (default: '123qwe')
  • MYSQL_DATABASE: MySQL database name (default: 'mcpdb')

Database Setup

  1. Create a MySQL database:
CREATE DATABASE mcpdb;
  1. Create a MySQL user with access to the database:
CREATE USER 'mcp101'@'localhost' IDENTIFIED BY '123qwe'; GRANT ALL PRIVILEGES ON mcpdb.* TO 'mcp101'@'localhost'; FLUSH PRIVILEGES;
  1. Create a test table with sample data:
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 Configuration

Add the MySQL MCP server to your MCP settings file:

VSCode (Claude Extension)

File: ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json

Change the args according your MySQL configuruation

{ "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" } } }

Claude Desktop App

File: ~/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" } } }

Usage

Once configured, you can use the MySQL MCP server in your conversations with Claude. For example:

"Can you show me all the users in the test_users table?"

Claude will use the run_sql_query tool to execute:

SELECT * FROM test_users

Available Tools

run_sql_query

Executes a read-only SQL query (SELECT statements only) against the MySQL database.

Parameters:

  • query: The SQL SELECT query to execute.

Example:

{ "query": "SELECT * FROM test_users" }

create_table

Creates a new table in the MySQL database.

Parameters:

  • query: The SQL CREATE TABLE query to execute.

Example:

{ "query": "CREATE TABLE products (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), price DECIMAL(10,2))" }

insert_data

Inserts data into a table in the MySQL database.

Parameters:

  • query: The SQL INSERT INTO query to execute.

Example:

{ "query": "INSERT INTO products (name, price) VALUES ('Laptop', 999.99), ('Smartphone', 499.99)" }

update_data

Updates data in a table in the MySQL database.

Parameters:

  • query: The SQL UPDATE query to execute.

Example:

{ "query": "UPDATE products SET price = 899.99 WHERE name = 'Laptop'" }

delete_data

Deletes data from a table in the MySQL database.

Parameters:

  • query: The SQL DELETE FROM query to execute.

Example:

{ "query": "DELETE FROM products WHERE name = 'Smartphone'" }

Security Considerations

  • Use a dedicated MySQL user with appropriate privileges for the MCP server
  • Consider using read-only privileges if you only need to query data
  • Store sensitive information like database credentials securely
  • All operations are logged with unique transaction IDs for auditing
Deploy Server
A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

AI 에이전트가 MySQL 데이터베이스에 대해 SQL 쿼리를 실행하여 데이터 읽기, 테이블 생성, 레코드 삽입, 업데이트, 삭제와 같은 작업을 지원할 수 있는 모델 컨텍스트 프로토콜 서버입니다.

  1. 특징
    1. 필수 조건
      1. 설치
        1. 구성
          1. 데이터베이스 설정
            1. MCP 구성
              1. VSCode(Claude 확장)
              2. 클로드 데스크톱 앱
            2. 용법
              1. 사용 가능한 도구
                1. SQL 쿼리 실행
                2. 테이블 생성
                3. 삽입_데이터
                4. 업데이트_데이터
                5. 데이터 삭제
              2. 보안 고려 사항

                Related MCP Servers

                • A
                  security
                  A
                  license
                  A
                  quality
                  A 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.
                  Last updated -
                  5
                  385
                  MIT License
                • A
                  security
                  F
                  license
                  A
                  quality
                  A 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.
                  Last updated -
                  7
                • -
                  security
                  F
                  license
                  -
                  quality
                  A Model Context Protocol server that enables AI models to interact with MySQL databases through natural language, supporting SQL queries, table creation, and schema exploration.
                  Last updated -
                  3
                  • Linux
                  • Apple
                • A
                  security
                  A
                  license
                  A
                  quality
                  A 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.
                  Last updated -
                  4
                  73
                  10
                  MIT License

                View all related MCP servers

                MCP directory API

                We provide all the information about MCP servers via our MCP API.

                curl -X GET 'https://glama.ai/api/mcp/v1/servers/michael7736/mysql-mcp-server'

                If you have feedback or need assistance with the MCP directory API, please join our Discord server