The MCP-MySQL Server allows AI models to interact with MySQL databases through a standardized interface. You can:
Connect to MySQL databases using URLs, workspace paths (via
.envfiles), or direct credentialsExecute SELECT queries with support for prepared statement parameters
Perform INSERT, UPDATE, or DELETE operations with prepared statement support
List all tables in the connected database
Describe table structures to view columns, types, and other details
Create new tables with specified fields and indexes
Add new columns to existing tables
Prevent SQL injection through prepared statements and secure connection handling
Manage database schema efficiently
The MCP server supports reading database configuration from .env files to manage database connection parameters
Allows AI models to interact with MySQL databases through a standardized interface, providing operations like querying, executing updates, listing tables, describing table structure, and creating tables
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP-MySQL Serverlist all tables in the database"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
@enemyrr/mcp-mysql-server
A Model Context Protocol server that provides MySQL database operations. This server enables AI models to interact with MySQL databases through a standardized interface.
Installation & Setup for Cursor IDE
Installing via Smithery
To install MySQL Database Server for Claude Desktop automatically via Smithery:
Installing Manually
Clone and build the project:
Add the server in Cursor IDE settings:
Open Command Palette (Cmd/Ctrl + Shift + P)
Search for "MCP: Add Server"
Fill in the fields:
Name:
mysqlType:
commandCommand:
node /absolute/path/to/mcp-mysql-server/build/index.js
Note: Replace
/absolute/path/to/with the actual path where you cloned and built the project.
Related MCP server: MySql MCP Server
Database Configuration
You can configure the database connection in three ways:
Database URL in .env (Recommended):
Individual Parameters in .env:
Direct Connection via Tool:
Available Tools
1. connect_db
Connect to MySQL database using URL, workspace path, or direct credentials.
2. query
Execute SELECT queries with optional prepared statement parameters.
3. execute
Execute INSERT, UPDATE, or DELETE queries with optional prepared statement parameters.
4. list_tables
List all tables in the connected database.
5. describe_table
Get the structure of a specific table.
6. create_table
Create a new table with specified fields and indexes.
7. add_column
Add a new column to an existing table.
8. alter_column
Modify an existing column (type, nullable, default, or rename).
9. drop_column
Remove a column from a table.
10. drop_table
Delete a table (requires confirmation).
11. truncate_table
Remove all rows from a table (requires confirmation).
12. list_databases
List all accessible databases on the server.
13. get_indexes
List all indexes on a table.
14. get_foreign_keys
List all foreign key relationships for a table.
MCP Resources
Browse database schema as resources:
URI | Description |
| Database overview (table count, size) |
| List all tables with metadata |
| Table details (columns, indexes, FKs) |
| Column definitions |
| Index definitions |
| Sample 5 rows from table |
MCP Prompts
Pre-built prompts for common operations:
Prompt | Description |
| Build SELECT query for a table |
| Generate INSERT template |
| Generate UPDATE template |
| Natural language schema explanation |
| Index recommendations for a table |
Features
14 database tools for queries, schema management, and more
MCP Resources for browsing database schema
MCP Prompts for generating SQL queries
Multiple connection methods (URL, workspace, direct)
Secure connection handling with automatic cleanup
Prepared statement support for query parameters
Comprehensive error handling and validation
TypeScript support
Security
Uses prepared statements to prevent SQL injection
Supports secure password handling through environment variables
Validates queries before execution
Automatically closes connections when done
Error Handling
The server provides detailed error messages for:
Connection failures
Invalid queries or parameters
Missing configuration
Database errors
Schema validation errors
Contributing
Contributions are welcome! Please feel free to submit a Pull Request to https://github.com/enemyrr/mcp-mysql-server
License
MIT