mcp-mysql
MCP server from enemyrr/mcp-mysql-server
claude mcp add --transport stdio enemyrr-mcp-mysql-server node build/index.js \ --env DB_HOST="localhost" \ --env DB_USER="your_user" \ --env DB_DATABASE="your_database" \ --env DB_PASSWORD="your_password" \ --env DATABASE_URL="mysql://user:password@host:3306/database"
How to use
This MCP server, @enemyrr/mcp-mysql-server, exposes a standardized interface for interacting with a MySQL database through the Model Context Protocol. It provides a collection of tools that let AI models connect to a database, run queries, manage schema, and inspect database structures. Key capabilities include connecting to a database via a URL, workspace context, or direct credentials, executing parameterized SELECTs and DML statements, listing tables and databases, and performing schema changes such as adding or altering columns, creating tables, and dropping objects. The server is designed with prepared statements to prevent SQL injection and supports safe cleanup of connections after operations.
Available MCP tools:
- connect_db: Establish a connection to the MySQL database using a URL, workspace path, or direct credentials.
- query: Run SELECT queries with optional prepared statement parameters.
- execute: Run INSERT, UPDATE, or DELETE statements with optional prepared statement parameters.
- list_tables: Retrieve the list of tables in the connected database.
- describe_table: Get the structure of a specific table.
- create_table: Create a new table with specified fields and indexes.
- add_column: Add a new column to an existing table.
- alter_column: Modify an existing column (type, nullable, default, or rename).
- drop_column: Remove a column from a table.
- drop_table: Delete a table (requires confirmation).
- truncate_table: Remove all rows from a table (requires confirmation).
- list_databases: List all accessible databases on the server.
- get_indexes: List all indexes on a table.
- get_foreign_keys: List all foreign key relationships for a table.
MCP Resources let you browse the database schema as resources (schemas, tables, columns, indexes, and samples). MCP Prompts provide templates to generate SELECT, INSERT, UPDATE queries and explain the schema or suggest indexes. These tools enable AI models to perform typical database tasks end-to-end through a consistent MCP interface.
How to install
Prerequisites:
- Node.js (LTS) and npm installed on your system
- Git
- Optional: a MySQL server to connect to
Install via npm/npx (recommended):
- Install the package and run the built server via Smithery (if applicable):
npx -y @smithery/cli install @enemyrr/mcp-mysql-server --client claude
Manual installation (from source):
- Clone the repository and install dependencies
git clone https://github.com/enemyrr/mcp-mysql-server.git
cd mcp-mysql-server
npm install
- Build the project (produces build/index.js and related files)
npm run build
- Run the server locally (example)
node build/index.js
Cursor IDE setup (optional):
- In Cursor IDE, add the MCP server with:
- Name: mysql
- Type: command
- Command: node /absolute/path/to/mcp-mysql-server/build/index.js
Configuration: prepare a .env or environment variables as described in the next section to supply database connection details.
Additional notes
Tips and caveats:
- Use DATABASE_URL for a concise connection string; alternatively, set DB_HOST, DB_USER, DB_PASSWORD, and DB_DATABASE for granular configuration.
- Ensure your environment variables are securely managed and not committed to version control.
- The server uses prepared statements by default to protect against SQL injection.
- For production deployments, consider configuring TLS/SSL options on the MySQL connection if supported by your driver.
- If you encounter connection errors, verify that the MySQL user has appropriate privileges and that network access from the MCP server host is allowed.
- When performing destructive operations (drop_table, truncate_table), always use the confirm flag to avoid accidental data loss.
- If you need to switch databases or hosts, update the environment variables or the DATABASE_URL accordingly and restart the MCP server.
Related MCP Servers
iterm
A Model Context Protocol server that executes commands in the current iTerm session - useful for REPL and CLI assistance
mcp
Octopus Deploy Official MCP Server
furi
CLI & API for MCP management
editor
MCP Server for Phaser Editor
DoorDash
MCP server from JordanDalton/DoorDash-MCP-Server
mcp
MCP сервер для автоматического создания и развертывания приложений в Timeweb Cloud