This MCP MySQL Server provides a standardized interface for AI models to interact with MySQL databases, enabling database operations through the Model Context Protocol. It's designed to work seamlessly with tools like Claude Desktop and Cursor IDE.
The easiest way to install the MySQL Database Server is automatically via Smithery:
npx -y @smithery/cli install @enemyrr/mcp-mysql-server --client claude
If you prefer a manual installation:
git clone https://github.com/enemyrr/mcp-mysql-server.git
cd mcp-mysql-server
npm install
npm run build
mysql
command
node /absolute/path/to/mcp-mysql-server/build/index.js
Note: Replace /absolute/path/to/
with the actual path where you cloned the project.
You can configure your database connection in three different ways:
DATABASE_URL=mysql://user:password@host:3306/database
DB_HOST=localhost
DB_USER=your_user
DB_PASSWORD=your_password
DB_DATABASE=your_database
use_mcp_tool({
server_name: "mysql",
tool_name: "connect_db",
arguments: {
url: "mysql://user:password@host:3306/database"
// OR
workspace: "/path/to/your/project" // Will use project's .env
// OR
host: "localhost",
user: "your_user",
password: "your_password",
database: "your_database"
}
});
Before executing any queries, you need to connect to your database:
use_mcp_tool({
server_name: "mysql",
tool_name: "connect_db",
arguments: {
url: "mysql://user:password@host:3306/database"
}
});
To retrieve data from the database:
use_mcp_tool({
server_name: "mysql",
tool_name: "query",
arguments: {
sql: "SELECT * FROM users WHERE id = ?",
params: [1]
}
});
To insert, update, or delete data:
use_mcp_tool({
server_name: "mysql",
tool_name: "execute",
arguments: {
sql: "INSERT INTO users (name, email) VALUES (?, ?)",
params: ["John Doe", "[email protected]"]
}
});
use_mcp_tool({
server_name: "mysql",
tool_name: "list_tables"
});
use_mcp_tool({
server_name: "mysql",
tool_name: "describe_table",
arguments: {
table: "users"
}
});
use_mcp_tool({
server_name: "mysql",
tool_name: "create_table",
arguments: {
table: "users",
fields: [
{
name: "id",
type: "int",
autoIncrement: true,
primary: true
},
{
name: "email",
type: "varchar",
length: 255,
nullable: false
}
],
indexes: [
{
name: "email_idx",
columns: ["email"],
unique: true
}
]
}
});
use_mcp_tool({
server_name: "mysql",
tool_name: "add_column",
arguments: {
table: "users",
field: {
name: "phone",
type: "varchar",
length: 20,
nullable: true
}
}
});
The MCP MySQL server implements several security features:
When using the server, always ensure your database credentials are stored securely and not committed to version control.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "mysql" '{"command":"node","args":["/absolute/path/to/mcp-mysql-server/build/index.js"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"mysql": {
"command": "node",
"args": [
"/absolute/path/to/mcp-mysql-server/build/index.js"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"mysql": {
"command": "node",
"args": [
"/absolute/path/to/mcp-mysql-server/build/index.js"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect