Node.js-based MySQL database integration that provides secure MySQL database operations
Harness the power of your Large Language Models (LLMs) by connecting them directly to your MySQL databases using the Model Context Protocol (MCP). This guide introduces the @f4ww4z/mcp-mysql-server
, a robust and secure MCP server that empowers your AI applications with real-time data access and manipulation capabilities.
This server provides a standardized interface for LLMs to interact with MySQL databases, enabling a wide range of applications, from AI-powered data analysis to intelligent automation workflows.
Choose the installation method that best suits your workflow:
Leverage the simplicity of Smithery for effortless installation, especially for Claude Desktop users:
npx -y @smithery/cli install @f4ww4z/mcp-mysql-server --client claude
This command automates the installation process, configuring the server for seamless integration with your Claude environment.
For users who prefer a more hands-on approach, manual installation offers greater control over the configuration process:
npx @f4ww4z/mcp-mysql-server
Follow the subsequent configuration steps to ensure proper setup.
To establish a connection between the MCP server and your MySQL database, you need to configure the following environment variables within your MCP settings configuration file (typically mcp.config.json
or similar):
{ "mcpServers": { "mysql": { "command": "npx", "args": ["-y", "@f4ww4z/mcp-mysql-server"], "env": { "MYSQL_HOST": "your_host", "MYSQL_USER": "your_user", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database" } } } }
Explanation of Configuration Parameters:
MYSQL_HOST
: The hostname or IP address of your MySQL server.MYSQL_USER
: The username for connecting to the MySQL database.MYSQL_PASSWORD
: The password for the specified MySQL user.MYSQL_DATABASE
: The name of the database you want to access.Important Security Note: Storing passwords directly in configuration files is generally discouraged. Consider using environment variables or a secrets management solution for enhanced security.
The @f4ww4z/mcp-mysql-server
provides a suite of powerful tools that enable your LLMs to interact with your MySQL database. These tools are accessed using the use_mcp_tool
function within your LLM application.
General Usage Pattern:
use_mcp_tool({ server_name: "mysql", // Specifies the MySQL MCP server tool_name: "tool_name", // The name of the tool to use (see below) arguments: { // Tool-specific arguments // ... arguments for the specific tool } });
Here's a breakdown of the available tools:
connect_db
: Establishing the ConnectionThis tool establishes a connection to your MySQL database using the provided credentials. While the server automatically manages connections, this tool can be used for explicit connection management or testing.
use_mcp_tool({ server_name: "mysql", tool_name: "connect_db", arguments: { host: "localhost", user: "your_user", password: "your_password", database: "your_database" } });
Note: The host
, user
, password
, and database
arguments are optional if already defined in the environment variables.
query
: Executing SELECT StatementsThis tool allows you to execute SELECT
queries against your database. It supports prepared statements for secure and efficient data retrieval.
use_mcp_tool({ server_name: "mysql", tool_name: "query", arguments: { sql: "SELECT * FROM users WHERE id = ?", params: [1] } });
sql
: The SQL SELECT
query to execute. Use ?
placeholders for prepared statement parameters.params
: An array of values to substitute for the ?
placeholders in the sql
query.execute
: Performing Data Manipulation (INSERT, UPDATE, DELETE)This tool enables you to execute INSERT
, UPDATE
, and DELETE
queries to modify data within your database. It also supports prepared statements for security and efficiency.
use_mcp_tool({ server_name: "mysql", tool_name: "execute", arguments: { sql: "INSERT INTO users (name, email) VALUES (?, ?)", params: ["John Doe", "[email protected]"] } });
sql
: The SQL INSERT
, UPDATE
, or DELETE
query to execute. Use ?
placeholders for prepared statement parameters.params
: An array of values to substitute for the ?
placeholders in the sql
query.list_tables
: Discovering Your Database SchemaThis tool retrieves a list of all tables within the connected database.
use_mcp_tool({ server_name: "mysql", tool_name: "list_tables", arguments: {} });
This tool requires no arguments.
describe_table
: Understanding Table StructureThis tool provides detailed information about the structure of a specific table, including column names, data types, and constraints.
use_mcp_tool({ server_name: "mysql", tool_name: "describe_table", arguments: { table: "users" } });
table
: The name of the table to describe.The @f4ww4z/mcp-mysql-server
is designed with performance, security, and ease of use in mind:
Security is paramount when connecting LLMs to databases. The @f4ww4z/mcp-mysql-server
incorporates several security measures:
The server provides informative error messages to help you diagnose and resolve issues quickly. Common error scenarios include:
We welcome contributions to the @f4ww4z/mcp-mysql-server
project! If you have bug fixes, new features, or improvements to suggest, please submit a pull request to https://github.com/f4ww4z/mcp-mysql-server.
By integrating the @f4ww4z/mcp-mysql-server
into your LLM applications, you can unlock a new level of intelligence and automation, enabling your models to interact with real-world data in a secure and efficient manner.
๐ โ๏ธ Biomedical research server providing access to PubMed, ClinicalTrials.gov, and MyVariant.info.
๐ MCP server that provides SQL analysis, linting, and dialect conversion using [SQLGlot](https://github.com/tobymao/sqlglot)
๐ ๐ All-in-one MCP server for Postgres development and operations, with tools for performance analysis, tuning, and health checks
Supabase MCP Server with support for SQL query execution and database exploration tools