database-mcp-mysql — Claude Code MCP server: how to install
Connects AI assistants to MySQL instances with read-only safeguards. Useful for exploring schemas and inspecting data without write hazards.
claude mcp add database-mcp-mysql -e MYSQL_HOST=<MYSQL_HOST> -e MYSQL_USER=<MYSQL_USER> -e MYSQL_PASSWORD=<MYSQL_PASSWORD> -e MYSQL_DATABASE=<MYSQL_DATABASE> -- npx -y @database-mcp/mysqlWhat database-mcp-mysql does
The server provides two tools for AI models: search_objects and execute_sql. Running the schema inspector without arguments outputs table names. Supplying a table name reveals its column types, indexes, and foreign keys. The second tool runs the queries.
Safeguards protect against database mutations on two fronts. The tool checks statements before execution and sets a read-only session inside MySQL. Default limits restrict output to 1000 rows and stop commands after 30 seconds.
Database credentials cannot be passed inside chat prompts. The process reads configuration exclusively on startup from flags, a YAML document, or MYSQL_* environment variables.
What it helps with
- inspect MySQL tables, indexes, and foreign keys
- run analytical SQL queries without accidental writes
- cut off slow database statements with a 30-second timeout
- keep connection passwords out of application logs
Example prompts for the agent
- Inspect the schema of the customers table and list its indexes.
- Find the five most recent entries in the orders table.
- List every table present in the current MySQL database.
How to install database-mcp-mysql
Platform CLI
claude mcp add database-mcp-mysql -e MYSQL_HOST=<MYSQL_HOST> -e MYSQL_USER=<MYSQL_USER> -e MYSQL_PASSWORD=<MYSQL_PASSWORD> -e MYSQL_DATABASE=<MYSQL_DATABASE> -- npx -y @database-mcp/mysqlReplace <…> with your own values
Platform CLI
codex mcp add database-mcp-mysql --env MYSQL_HOST=<MYSQL_HOST> --env MYSQL_USER=<MYSQL_USER> --env MYSQL_PASSWORD=<MYSQL_PASSWORD> --env MYSQL_DATABASE=<MYSQL_DATABASE> -- npx -y @database-mcp/mysqlReplace <…> with your own values
Config file
{
"mcpServers": {
"database-mcp-mysql": {
"command": "npx",
"args": [
"-y",
"@database-mcp/mysql"
],
"env": {
"MYSQL_HOST": "<MYSQL_HOST>",
"MYSQL_USER": "<MYSQL_USER>",
"MYSQL_PASSWORD": "<MYSQL_PASSWORD>",
"MYSQL_DATABASE": "<MYSQL_DATABASE>"
}
}
}
}Replace <…> with your own values
Config file
{
"servers": {
"database-mcp-mysql": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@database-mcp/mysql"
],
"env": {
"MYSQL_HOST": "<MYSQL_HOST>",
"MYSQL_USER": "<MYSQL_USER>",
"MYSQL_PASSWORD": "<MYSQL_PASSWORD>",
"MYSQL_DATABASE": "<MYSQL_DATABASE>"
}
}
}
}Replace <…> with your own values
Platform CLI
gemini mcp add -e MYSQL_HOST=<MYSQL_HOST> -e MYSQL_USER=<MYSQL_USER> -e MYSQL_PASSWORD=<MYSQL_PASSWORD> -e MYSQL_DATABASE=<MYSQL_DATABASE> database-mcp-mysql npx -y @database-mcp/mysqlReplace <…> with your own values
Step by step, with commands for each platform: How to add an MCP server to Claude Code, Codex, Cursor, VS Code, Gemini CLI and more
Questions about database-mcp-mysql
How to install database-mcp-mysql in Claude Code?
Run `claude mcp add database-mcp-mysql -e MYSQL_HOST=<MYSQL_HOST> -e MYSQL_USER=<MYSQL_USER> -e MYSQL_PASSWORD=<MYSQL_PASSWORD> -e MYSQL_DATABASE=<MYSQL_DATABASE> -- npx -y @database-mcp/mysql`. Replace placeholder tags with actual MySQL credentials.
What does database-mcp-mysql do?
It exposes MySQL to coding agents via two tools: search_objects to explore schemas and execute_sql to fetch data safely.
Can I supply database passwords inside the conversation?
No, the server rejects credentials sent through prompts. All connection details must be configured upfront via environment variables, flags, or YAML files.