The MySQL MCP server provides access to MySQL databases through the Model Context Protocol, allowing agents to execute various SQL queries and receive results in JSON format. This integration enables seamless interaction with MySQL databases directly through Claude.
Install the MySQL MCP server by following these steps:
cd mysql-mcp-server
npm install
npm run build
The MySQL MCP server is configured using environment variables:
MYSQL_HOST
: MySQL server hostname (default: 'localhost')MYSQL_PORT
: MySQL server port (default: 3306)MYSQL_USER
: MySQL username (default: 'mcp101')MYSQL_PASSWORD
: MySQL password (default: '123qwe')MYSQL_DATABASE
: MySQL database name (default: 'mcpdb')CREATE DATABASE mcpdb;
CREATE USER 'mcp101'@'localhost' IDENTIFIED BY '123qwe';
GRANT ALL PRIVILEGES ON mcpdb.* TO 'mcp101'@'localhost';
FLUSH PRIVILEGES;
USE mcpdb;
CREATE TABLE test_users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO test_users (name, email) VALUES
('John Doe', '[email protected]'),
('Jane Smith', '[email protected]'),
('Bob Johnson', '[email protected]');
Add the MySQL MCP server to your MCP settings file:
Location: ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
{
"mcpServers": {
"mysql-mcp-server": {
"autoApprove": [],
"disabled": false,
"timeout": 60,
"command": "node",
"args": [
"/path/to/mysql-mcp-server/build/index.js"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "mcp101",
"MYSQL_PASSWORD": "123qwe",
"MYSQL_DATABASE": "mcpdb"
},
"transportType": "stdio"
}
}
}
Location: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"mysql-mcp-server": {
"autoApprove": [],
"disabled": false,
"timeout": 60,
"command": "node",
"args": [
"/path/to/mysql-mcp-server/build/index.js"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "mcp101",
"MYSQL_PASSWORD": "123qwe",
"MYSQL_DATABASE": "mcpdb"
},
"transportType": "stdio"
}
}
}
Once configured, you can use the MySQL MCP server in conversations with Claude. For example, you can ask:
"Can you show me all the users in the test_users table?"
Claude will use the run_sql_query
tool to execute:
SELECT * FROM test_users
Executes a read-only SQL query (SELECT statements only) against the MySQL database.
Parameters:
query
: The SQL SELECT query to execute.Example:
{
"query": "SELECT * FROM test_users"
}
Creates a new table in the MySQL database.
Parameters:
query
: The SQL CREATE TABLE query to execute.Example:
{
"query": "CREATE TABLE products (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), price DECIMAL(10,2))"
}
Inserts data into a table in the MySQL database.
Parameters:
query
: The SQL INSERT INTO query to execute.Example:
{
"query": "INSERT INTO products (name, price) VALUES ('Laptop', 999.99), ('Smartphone', 499.99)"
}
Updates data in a table in the MySQL database.
Parameters:
query
: The SQL UPDATE query to execute.Example:
{
"query": "UPDATE products SET price = 899.99 WHERE name = 'Laptop'"
}
Deletes data from a table in the MySQL database.
Parameters:
query
: The SQL DELETE FROM query to execute.Example:
{
"query": "DELETE FROM products WHERE name = 'Smartphone'"
}
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.