A Model Context Protocol server for MySQL database operations
Configuration
View docs{
"mcpServers": {
"f4ww4z-mcp-mysql-server": {
"command": "npx",
"args": [
"-y",
"@f4ww4z/mcp-mysql-server",
"mysql://user:password@localhost:port/database"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_USER": "db_user",
"MYSQL_DATABASE": "my_db",
"MYSQL_PASSWORD": "secret"
}
}
}
}You can use this MCP server to enable AI models to perform MySQL database operations through a standardized interface. It handles secure connections, prepared statements, and automatic connection management so you can focus on data tasks like querying and updating your MySQL databases.
You interact with the MySQL MCP server through an MCP client. Start by configuring your client to connect to the server, then issue common data actions such as connecting to the database, running SELECT queries, performing INSERT/UPDATE/DELETE operations, listing tables, and inspecting table structures. The server automatically manages connections and cleans up resources after each operation, keeping interactions simple and secure.
Prerequisites: you need Node.js and npm installed on your machine.
Step 1: Install and run the MCP server locally with the npx command.
Step 2: If you want Claude Desktop to use the server automatically, install via the Smithery CLI.
Step 3: Ensure the server is running and reachable from your MCP client.
The server can be configured in your MCP settings with either a direct URL or environment variables for the host, user, password, and database. Use the following configuration shapes to connect via your MCP client.
Use one of the following configurations to connect the MCP client to the MySQL MCP server.
{
"mcpServers": {
"mysql": {
"type": "stdio",
"name": "mysql",
"command": "npx",
"args": ["-y", "@f4ww4z/mcp-mysql-server", "mysql://user:password@localhost:port/database"]
}
}
}Or, supply credentials via environment variables (recommended for security):
{
"mcpServers": {
"mysql": {
"type": "stdio",
"name": "mysql",
"command": "npx",
"args": ["-y", "@f4ww4z/mcp-mysql-server"],
"env": {
"MYSQL_HOST": "your_host",
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database"
}
}
}
}The server uses prepared statements to prevent SQL injection and validates queries before execution. Passwords and sensitive data should be provided through environment variables to avoid exposure in configuration files. Connections are automatically closed when operations finish.
If a connection fails, a query is invalid, or a database error occurs, you will receive a detailed error message that guides you to resolve the issue and safe-guard your operations.
If you cannot reach the server, verify that the host, port, and database name are correct. Check that environment variables are correctly set when using the env-based configuration. Ensure your MCP client is configured to target the correct server name (mysql) and that the server process is running.
The server exposes tools to connect, query, execute updates, list tables, and describe table structures. Use these actions to manage data in your MySQL databases.
If you want to run evaluations or tests against the server, use the provided eval workflow by setting your API key and invoking the evaluation script as shown in the execution flow.
Establish a connection to the MySQL database using provided credentials.
Execute SELECT queries with optional prepared statement parameters.
Execute INSERT, UPDATE, or DELETE queries with optional prepared statement parameters.
List all tables in the connected database.
Get the structure of a specific table.