MySQL MCP Server

MySQL MCP Server
Connect Claude to your MySQL database through the Model Context Protocol.

MySQL MCP Server

Connect Claude to your MySQL database through the Model Context Protocol.

The MySQL MCP Server enables Claude to run queries, explore database schemas, and interact with your MySQL data using natural language commands.

What Can Claude Do with the MySQL MCP Server?

The MySQL MCP Server exposes MySQL database operations to Claude through the Model Context Protocol.

Core capabilities:

  • Run Queries — Execute SELECT queries to retrieve data
  • Explore Schemas — View table structures, column types, and relationships
  • List Databases & Tables — Browse available databases and table names
  • Inspect Data — Preview table contents and row samples
  • Execute Statements — Run INSERT, UPDATE, DELETE operations (if permitted)

Access scope: Claude can only perform operations your MySQL user credentials allow. The integration respects MySQL user permissions, database access, and privilege grants.

How to Install the MySQL MCP Server

Installation requires MySQL connection credentials.

Important: the mysql-mcp-server package commonly used in examples is a community package, not an official MySQL product.

For Claude Code

If you choose that community package, install it explicitly as a community implementation and review the repository before using it against production data.

bash
claude mcp add mysql npx -y mysql-mcp-server

For Claude Desktop

Add the server to your claude_desktop_config.json file with your MySQL connection details:

Configuration file locations:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Typical configuration structure:

json
{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "mysql-mcp-server"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "your_username",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database_name"
      }
    }
  }
}

Use the package README as the source of truth for required environment variables, and keep the "community package" status clear in internal documentation.

Alternative connection string format:

Some implementations may support a single connection string:

json
"env": {
  "MYSQL_CONNECTION_STRING": "mysql://username:password@localhost:3306/database_name"
}

Important security notes:

  • Never commit database credentials to version control
  • Use read-only database users for querying only
  • Consider creating dedicated MySQL users with minimal necessary privileges
  • For production databases, use extremely restricted permissions

Restart Claude Desktop after saving the configuration file.

MySQL Connection String Setup for MCP

The MySQL MCP Server requires database connection credentials.

Connection parameters:

  • MYSQL_HOST — Database server hostname or IP address (e.g., localhost, db.example.com)
  • MYSQL_PORT — MySQL port number (default: 3306)
  • MYSQL_USER — MySQL username for authentication
  • MYSQL_PASSWORD — User password
  • MYSQL_DATABASE — Default database to connect to

Creating a dedicated MySQL user:

For security, create a dedicated user for the MCP Server:

sql
-- Create read-only user
CREATE USER 'claude_readonly'@'localhost' IDENTIFIED BY 'secure_password';
GRANT SELECT ON your_database.* TO 'claude_readonly'@'localhost';
FLUSH PRIVILEGES;

-- Create read-write user (use cautiously)
CREATE USER 'claude_readwrite'@'localhost' IDENTIFIED BY 'secure_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON your_database.* TO 'claude_readwrite'@'localhost';
FLUSH PRIVILEGES;

Permission levels:

  • Read-only (SELECT only) — Recommended for most use cases. Claude can query but not modify data.
  • Read-write (SELECT, INSERT, UPDATE, DELETE) — Use only when modification is necessary. Monitor usage carefully.
  • Full privileges (including DROP, CREATE) — Not recommended. Risk of accidental data loss or schema changes.

Connection security:

  • Use SSL/TLS connections for remote databases
  • Whitelist IP addresses in MySQL firewall rules
  • Use strong passwords for database users
  • Rotate credentials periodically
  • Monitor database access logs

Testing the connection:

After configuration, verify the connection works:

sql
-- Test query to verify access
SELECT DATABASE(), USER(), VERSION();

MySQL MCP Query Examples & Use Cases

Example workflows that become possible with the MySQL MCP Server.

Explore Database Schema

Example prompt:

> "Show me all tables in the database and their column structures."

Claude can retrieve schema information and table definitions.

Query Table Data

Example prompt:

> "Select all customers from the customers table where country is 'USA' and created_at is within the last 30 days."

Claude can run SELECT queries based on your natural language description.

Count Records

Example prompt:

> "How many orders are in the orders table with status 'completed'?"

Claude can perform aggregation queries.

Join Multiple Tables

Example prompt:

> "Show me customer names and their order totals by joining the customers and orders tables."

Claude can construct JOIN queries across related tables.

Preview Table Contents

Example prompt:

> "Show me the first 10 rows from the products table."

Claude can sample table data for inspection.

Search by Criteria

Example prompt:

> "Find all users with email addresses ending in '@company.com'."

Claude can build WHERE clauses based on search criteria.

Insert New Records

Example prompt:

> "Add a new record to the tasks table with title 'Review documentation' and status 'pending'."

Claude can execute INSERT statements if your user has write permissions.

Important security note: Write operations (INSERT, UPDATE, DELETE) should be used with extreme caution. Always verify queries before execution on production databases.

Note: These are example use cases. Actual capabilities depend on your MySQL user permissions and the MCP server implementation. Schema exploration and SELECT queries are typically the safest operations.

MySQL MCP in a Production Data Workflow

MySQL MCP is most practical when assistants need to query, inspect, and troubleshoot live relational data used by an application.

What this shows: This screenshot points to a real MySQL MCP implementation, which matches production scenarios like schema inspection, query assistance, and data debugging.

Why this scenario matters: It ties the article to a real database workflow surface, where agents become useful for inspection, troubleshooting, and query assistance against live relational data.

Typical assistant task: Inspect schema details, reason about relational data, and support query-heavy troubleshooting against application databases.

Source: MySQL MCP Repository

When to Pick MySQL MCP Server vs PostgreSQL

This comparison is most useful when both options look plausible on paper but differ in operating model, team fit, and day-to-day workflow cost.

Decision LensThis Page's MCP PathCompetitor
Best ForTeams already running MySQL-backed applications and operational playbooks around that environment.Teams that want a deeper extensibility story and a broader advanced-SQL ecosystem.
Where MCP WinsMySQL MCP wins when the real requirement is assistant access to an existing MySQL estate, not a database migration decision.
Tradeoff to WatchIt is a less natural fit when the team’s real need maps to PostgreSQL-centric features and ecosystem depth.
Choose This Path WhenChoose MySQL MCP when MySQL is already the live runtime; choose PostgreSQL-oriented paths when extensibility is the bigger priority.
Sources

Frequently Asked Questions

Is the MySQL MCP Server safe to use with production databases?
Use extreme caution with production databases. Create read-only users and test thoroughly in development environments first. Write operations on production data carry significant risk.
Can Claude execute any SQL query?
Claude can execute queries your MySQL user has permissions for. Use read-only users to restrict operations to SELECT queries only.
Does it work with remote MySQL servers?
Yes. Specify the remote hostname or IP address in the connection configuration. Ensure your firewall allows connections and consider using SSL/TLS.
What about SQL injection risks?
The MCP Server implementation should use parameterized queries. However, always use minimal necessary permissions as an additional security layer.
Does it work with MySQL-compatible databases?
Compatibility depends on the MCP server implementation. MariaDB and other MySQL-compatible databases may work, but check the server's documentation for supported systems.
Can Claude see multiple databases?
Access depends on your MySQL user's GRANT permissions. A user can be granted access to multiple databases.
What's the difference between localhost and 127.0.0.1?
localhost resolves to the local machine, typically using Unix sockets. 127.0.0.1 forces a TCP/IP connection. Both work for local MySQL, but socket connections may be faster.
How do I secure my database password in the config file?
Use environment variables, secrets management tools, or encrypted configuration files. Never commit credentials to version control.

Use MySQL MCP in Verdent

Verdent provides streamlined MySQL integration with secure credential management. This is Verdent's platform-level integration flow, not the default setup path from MySQL MCP implementations.

Connect your MySQL database once with encrypted credentials and access query capabilities across all Verdent projects without storing passwords in plain text configuration files.

Connect MySQL in Verdent