Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
connect_db
✓ await use_mcp_tool({ server_name: "mysql", tool_name: "connect_db", arguments: { url: "mysql://user:pass@host:3306/db" } })
✗ import { connect_db } from '@enemyrr/mcp-mysql-server'
This package is an MCP server; its functionality (tools like `connect_db`) is accessed via an MCP client's `use_mcp_tool` abstraction, not through direct JavaScript `import` or `require` statements from user application code.
query
✓ await use_mcp_tool({ server_name: "mysql", tool_name: "query", arguments: { sql: "SELECT * FROM users", params: [] } })
✗ const query = require('@enemyrr/mcp-mysql-server').query
The `query` tool for executing SELECT statements is exposed by the MCP server and invoked through the MCP client's API, facilitating AI model interaction with the database.
execute
✓ await use_mcp_tool({ server_name: "mysql", tool_name: "execute", arguments: { sql: "INSERT INTO logs (message) VALUES (?) ", params: ['test'] } })
✗ type ExecuteArgs = typeof import('@enemyrr/mcp-mysql-server')['execute']
Similar to other tools, the `execute` tool for DML operations (INSERT, UPDATE, DELETE) is a server capability accessed programmatically via the MCP client interface, not a directly importable function or type.
list_tables
✓ await use_mcp_tool({ server_name: "mysql", tool_name: "list_tables" })
✗ import { list_tables } from '@enemyrr/mcp-mysql-server/tools'
Server-provided tools like `list_tables` are part of the MCP contract. Direct file imports from the server package will fail and are not the intended interaction method.
Demonstrates connecting to a MySQL database using environment variables, executing a simple SELECT query, performing an INSERT statement, and listing database tables via the `use_mcp_tool` abstraction.
// This code assumes you are running within an environment that provides `use_mcp_tool`,
// such as Cursor IDE or a compatible AI agent framework.
// Ensure your .env file in the workspace root has DATABASE_URL=mysql://user:password@host:3306/database
// or individual DB_HOST, DB_USER, etc.
async function runDbOperations() {
console.log("Attempting to connect to MySQL...");
// 1. Connect to the database using environment variables from the workspace
const connectResult = await use_mcp_tool({
server_name: "mysql",
tool_name: "connect_db",
arguments: {
workspace: process.env.MCP_WORKSPACE_PATH ?? "./" // Uses .env from current directory
}
});
if (connectResult.status === 'success') {
console.log("Successfully connected to MySQL database.");
// 2. Execute a simple SELECT query
const selectQueryResult = await use_mcp_tool({
server_name: "mysql",
tool_name: "query",
arguments: {
sql: "SELECT 1 + 1 AS solution, CURRENT_USER() AS user;",
params: []
}
});
if (selectQueryResult.status === 'success') {
console.log("Select Query result:", selectQueryResult.data);
} else {
console.error("Select Query failed:", selectQueryResult.error);
}
// 3. Example: Execute an INSERT statement (requires a 'test_table' or similar)
// Ensure a table exists, e.g., CREATE TABLE test_table (id INT AUTO_INCREMENT PRIMARY KEY, message VARCHAR(255));
const insertQueryResult = await use_mcp_tool({
server_name: "mysql",
tool_name: "execute",
arguments: {
sql: "INSERT INTO test_table (message) VALUES (?)",
params: ["Hello from MCP MySQL Server!"]
}
});
if (insertQueryResult.status === 'success') {
console.log("Insert Query successful. Rows affected:", insertQueryResult.data.rowsAffected);
} else {
console.error("Insert Query failed:", insertQueryResult.error);
}
// 4. List all tables in the connected database
const listTablesResult = await use_mcp_tool({
server_name: "mysql",
tool_name: "list_tables"
});
if (listTablesResult.status === 'success') {
console.log("Tables in database:", listTablesResult.data);
} else {
console.error("List tables failed:", listTablesResult.error);
}
} else {
console.error("Failed to connect to MySQL database:", connectResult.error);
}
}
// In a real AI agent context, this function would be called implicitly or explicitly by the agent.
runDbOperations();
Errors
Common errors & fixes
Error: connect ECONNREFUSED
The MySQL server is not running or is inaccessible from the host running the MCP server, or the specified host/port is incorrect.
fixEnsure the MySQL database server is active and reachable. Verify the `DB_HOST` and `DB_PORT` (default 3306) in your `.env` configuration or `connect_db` arguments.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'user'@'host' (using password: YES/NO)
Incorrect username or password provided for the MySQL database connection.
fixDouble-check the `DB_USER` and `DB_PASSWORD` variables in your `.env` file or `connect_db` arguments against your MySQL user credentials.
Error: ER_BAD_DB_ERROR: Unknown database 'your_database'
The specified database name in the connection string or parameters does not exist on the MySQL server.
fixVerify that the `DB_DATABASE` variable in your `.env` file or the `database` argument in `connect_db` matches an existing database on your MySQL server. Create the database if it's missing.
MCP server 'mysql' not found (when calling `use_mcp_tool`)
The `mcp-mysql-server` has not been correctly registered or configured within your MCP client environment (e.g., Cursor IDE).
fixFollow the 'Installation & Setup for Cursor IDE' steps in the README. Ensure the `Name` field for the server is exactly `mysql` and the `Command` path points to the correct `index.js` build file of the cloned project.
Audit
Dependencies
mysql2requiredRuntime dependency for connecting to and interacting with MySQL databases.
dotenvrequiredRequired for loading database connection configurations from .env files, as recommended for setup.