The MCP MySQL Server is a service that allows AI models to interact with MySQL databases through a standardized interface based on the Model Context Protocol. It provides a secure and efficient way to execute database operations without exposing sensitive credentials to clients.
npx @malove86/mcp-mysql-server
The server supports two deployment modes:
In your MCP configuration file, specify the command line settings:
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "@malove86/mcp-mysql-server"],
"env": {
"MYSQL_HOST": "your_host",
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database",
"MYSQL_PORT": "3306"
}
}
}
}
Point to a remotely running MCP server:
{
"mcpServers": {
"mcp-mysql-server": {
"url": "http://your-server-address:port/mcp-mysql-server"
}
}
}
On the remote server, set environment variables before starting:
# Set environment variables
export MYSQL_HOST=your_host
export MYSQL_USER=your_user
export MYSQL_PASSWORD=your_password
export MYSQL_DATABASE=your_database
export MYSQL_PORT=3306 # Optional, defaults to 3306
# Start the server
npx @malove86/mcp-mysql-server
Note: The MYSQL_PORT
is optional and defaults to 3306.
Establishes a connection to the MySQL database using provided credentials. This tool is optional if connection details are set through environment variables.
{
"host": "localhost",
"user": "root",
"password": "your_password",
"database": "your_database",
"port": 3306 // Optional, defaults to 3306
}
Executes SELECT queries with optional prepared statement parameters.
{
"sql": "SELECT * FROM users WHERE id = ?",
"params": [1] // Optional parameters
}
Lists all tables in the connected database.
{} // No parameters needed as of v0.2.4
Gets the structure of a specific table.
{
"table": "users"
}
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 > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.