@yevlakhov/mysql-mcp
v1.0.0
Published
MCP server for MySQL/MariaDB database queries
Downloads
20
Maintainers
Readme
MySQL MCP Server
MCP (Model Context Protocol) server for MySQL/MariaDB that allows LLMs in AI IDEs (Cursor, VS Code with Copilot, etc.) to execute SQL queries against the database.
Installation
npm install -g @yevlakhov/mysql-mcpOr run via npx without installation:
npx @yevlakhov/mysql-mcpConfiguration in Cursor
Add to MCP servers settings (~/.cursor/mcp.json or in project settings):
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@yevlakhov/mysql-mcp"],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_username",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database",
"ALLOW_INSERT_OPERATION": "false",
"ALLOW_UPDATE_OPERATION": "false",
"ALLOW_DELETE_OPERATION": "false"
}
}
}
}Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| MYSQL_HOST | MySQL server host | 127.0.0.1 |
| MYSQL_PORT | MySQL server port | 3306 |
| MYSQL_USER | Username | root |
| MYSQL_PASSWORD | Password | empty string |
| MYSQL_DATABASE | Database name | empty string |
| ALLOW_INSERT_OPERATION | Allow INSERT queries | false |
| ALLOW_UPDATE_OPERATION | Allow UPDATE queries | false |
| ALLOW_DELETE_OPERATION | Allow DELETE queries | false |
Available Tools
mysql_query
Execute SELECT queries to read data.
Example: SELECT * FROM users WHERE id = ?mysql_insert
Execute INSERT queries (requires ALLOW_INSERT_OPERATION=true).
Example: INSERT INTO users (name, email) VALUES (?, ?)mysql_update
Execute UPDATE queries (requires ALLOW_UPDATE_OPERATION=true).
Example: UPDATE users SET name = ? WHERE id = ?mysql_delete
Execute DELETE queries (requires ALLOW_DELETE_OPERATION=true).
Example: DELETE FROM users WHERE id = ?mysql_describe
Get table structure (columns, types, keys).
mysql_list_tables
List all tables in the current database.
Security
- By default, INSERT, UPDATE and DELETE operations are disabled
- Each query is shown to the user and requires confirmation in the IDE
- Prepared statements are used for SQL injection protection
- It is recommended to use a database user with minimal required privileges
Usage Examples
After configuration, you can ask the AI in chat:
- "Show all tables in the database"
- "What is the structure of the users table?"
- "Select all users registered in the last month"
- "Add a new user with name John and email [email protected]"
The AI will automatically generate the SQL query and send it via MCP. Before executing the query, the IDE will display it and ask for confirmation.
Development
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build
npm run build
# Run built version
npm startLicense
MIT
