Last Updated: 2026-01-25 14:00:00
Version: 1.33.6
Total Tools: 150
Comprehensive documentation for the MySQL MCP Server. For quick start, see README.md.
- Configuration
- Tools Overview
- Permission System
- Tool Categories
- Core Operations
- Advanced Features
- Security Features
Configure MySQL MCP with two access-control layers:
{
"mcpServers": {
"mysql": {
"command": "npx",
"type": "stdio",
"args": [
"-y",
"@berthojoris/mcp-mysql-server",
"mysql://user:password@localhost:3306/database",
"list,read,utility",
"database_discovery,performance_monitoring"
]
}
}
}Layer 1 (Permissions): Broad operation control
Layer 2 (Categories): Fine-grained tool filtering
{
"env": {
"DB_HOST": "localhost",
"DB_PORT": "3306",
"DB_USER": "root",
"DB_PASSWORD": "your_password",
"DB_NAME": "your_database",
"MCP_PERMISSIONS": "list,read,utility",
"MCP_CATEGORIES": "database_discovery,performance_monitoring"
}
}| Permission | Operations | Example Tools |
|---|---|---|
list |
List/discover objects | list_databases, list_tables |
read |
Read data | read_records, run_select_query |
create |
Insert records | create_record, bulk_insert |
update |
Update records | update_record, bulk_update |
delete |
Delete records | delete_record, bulk_delete |
execute |
Custom SQL | execute_write_query |
ddl |
Schema changes | create_table, alter_table |
utility |
Utility operations | test_connection, analyze_table |
transaction |
Transaction management | begin_transaction, commit_transaction |
procedure |
Stored procedures | create_stored_procedure, execute_function |
Tool enabled = (Has Permission) AND (Has Category OR No categories specified)
list_databases- List all databaseslist_tables- List tables in databaseread_table_schema- Get table structureget_all_tables_relationships- Get all FK relationshipslist_all_tools- List available MCP tools
get_database_summary- AI-optimized database overviewget_schema_erd- Generate Mermaid.js ER diagramget_schema_rag_context- Compact schema for LLM contextget_column_statistics- Column data profiling
create_record- Insert single recordread_records- Query with filtering/paginationupdate_record- Update recordsdelete_record- Delete recordsbulk_insert- Batch insert (performance)bulk_update- Batch update (performance)bulk_delete- Batch delete (performance)
run_select_query- Execute SELECT queriesexecute_write_query- Execute INSERT/UPDATE/DELETErepair_query- Diagnose and fix SQL errors
create_table- Create new tablesalter_table- Modify table structuredrop_table- Delete tablesexecute_ddl- Execute raw DDL
list_indexes- List table indexesget_index_info- Get index detailscreate_index- Create indexesdrop_index- Drop indexescreate_fulltext_index- Create FULLTEXT indexes for text searchfulltext_search- Perform full-text search with MATCH AGAINSTget_fulltext_info- Get FULLTEXT index informationdrop_fulltext_index- Drop FULLTEXT indexesget_fulltext_stats- Get FULLTEXT index statisticsoptimize_fulltext- Optimize FULLTEXT indexes
list_foreign_keys- List foreign keyslist_constraints- List all constraintsadd_foreign_key- Add foreign keydrop_foreign_key- Remove foreign keyadd_unique_constraint- Add unique constraintdrop_constraint- Remove constraintadd_check_constraint- Add check constraint
list_stored_procedures- List proceduresget_stored_procedure_info- Get procedure detailsexecute_stored_procedure- Execute procedurescreate_stored_procedure- Create proceduresdrop_stored_procedure- Remove proceduresshow_create_procedure- Show CREATE statement
list_views- List viewsget_view_info- Get view detailscreate_view- Create viewsalter_view- Modify viewsdrop_view- Remove viewsshow_create_view- Show CREATE statement
list_triggers- List triggersget_trigger_info- Get trigger detailscreate_trigger- Create triggersdrop_trigger- Remove triggersshow_create_trigger- Show CREATE statement
list_functions- List functionsget_function_info- Get function detailscreate_function- Create functionsdrop_function- Remove functionsshow_create_function- Show CREATE statementexecute_function- Execute functions
analyze_table- Update statisticsoptimize_table- Reclaim spacecheck_table- Check for errorsrepair_table- Repair corrupted tablestruncate_table- Remove all rowsget_table_status- Get table statisticsflush_table- Close/reopen tableget_table_size- Get size information
begin_transaction- Start transactioncommit_transaction- Commit transactionrollback_transaction- Rollback transactionget_transaction_status- Check transaction stateexecute_in_transaction- Execute within transaction
get_performance_metrics- Get overall performance metricsget_top_queries_by_time- Get queries by execution timeget_top_queries_by_count- Get queries by execution countget_slow_queries- Get slow query logget_table_io_stats- Get table I/O statisticsget_index_usage_stats- Get index usage statisticsget_unused_indexes- Find unused indexesget_connection_pool_stats- Get connection pool statisticsget_database_health_check- Get database health statusreset_performance_stats- Reset performance statistics
analyze_query- Analyze query performanceget_optimization_hints- Get optimizer hintsrepair_query- Repair broken SQL queries
show_process_list- Show running processeskill_process- Terminate processesshow_status- Server status variablesshow_variables- Server configurationexplain_query- Query execution planshow_engine_status- Storage engine statusget_server_info- Comprehensive server infoshow_binary_logs- Show binary log filesshow_replication_status- Show replication status
get_cache_stats- Query cache statisticsget_cache_config- Cache configurationconfigure_cache- Configure cache settingsclear_cache- Clear cached results
export_table_to_csv- Export table to CSVexport_query_to_csv- Export query to CSVexport_table_to_json- Export table to JSONexport_query_to_json- Export query to JSONsafe_export_table- Export with PII maskingexport_table_to_sql- Export table to SQL dump
backup_table- Backup single tablebackup_database- Backup entire databaserestore_from_sql- Restore from SQL dumpget_create_table_statement- Get CREATE TABLEget_database_schema- Get complete schema
test_connection- Test connectivitydescribe_connection- Connection inforead_changelog- Read changeloginvalidate_table_cache- Clear table cache
import_from_csv- Import data from CSV fileimport_from_json- Import data from JSON file
copy_table_data- Copy data from one table to anothermove_table_data- Move data between tablesclone_table- Clone a table with its structure and datacompare_table_structure- Compare structure between two tablessync_table_data- Synchronize data between tables
init_migrations_table- Initialize migrations tracking tablecreate_migration- Create a new migrationapply_migrations- Apply pending migrationsrollback_migration- Rollback a specific migrationget_migration_status- Get migration statusget_schema_version- Get current schema versionvalidate_migrations- Validate migration filesreset_failed_migration- Reset a failed migrationgenerate_migration_from_diff- Generate migration from schema diff
build_query_from_intent- Convert natural language to SQLsuggest_query_improvements- Suggest query optimizationssmart_search- Semantic search for tables, columns, datafind_similar_columns- Find columns similar to a given columndiscover_data_patterns- Discover data patterns in tablesgenerate_documentation- Generate database documentationgenerate_data_dictionary- Generate data dictionary for tablesgenerate_business_glossary- Generate business glossarydesign_schema_from_requirements- Design schema from requirementsaudit_database_security- Audit database securityrecommend_indexes- Recommend indexes for optimizationgenerate_test_data- Generate test data for tablesanalyze_schema_patterns- Analyze schema design patternsvisualize_query- Visualize query execution planpredict_query_performance- Predict query performanceforecast_database_growth- Forecast database growth
Start with these tools to explore any database:
// List all databases
await mcp.call("list_databases", {});
// List tables in current database
await mcp.call("list_tables", {});
// Get comprehensive overview
await mcp.call("get_database_summary", {
max_tables: 50,
include_relationships: true
});
// Visualize relationships
await mcp.call("get_schema_erd", {});Basic CRUD operations:
// Create record
await mcp.call("create_record", {
table_name: "users",
data: { name: "John", email: "john@example.com" }
});
// Read with filtering
await mcp.call("read_records", {
table_name: "users",
filters: [{ field: "status", operator: "eq", value: "active" }],
pagination: { page: 1, limit: 10 }
});
// Update records
await mcp.call("update_record", {
table_name: "users",
data: { status: "inactive" },
conditions: [{ field: "last_login", operator: "lt", value: "2024-01-01" }]
});
// Delete records
await mcp.call("delete_record", {
table_name: "users",
conditions: [{ field: "status", operator: "eq", value: "deleted" }]
});// Analyze slow query
await mcp.call("analyze_query", {
query: "SELECT * FROM users WHERE email LIKE '%@gmail.com'"
});
// Get optimization hints
await mcp.call("get_optimization_hints", {
goal: "SPEED"
});The server includes AI-optimized tools for intelligent database analysis:
- Database Summary: Provides readable overviews with statistics
- ER Diagram Generation: Automatic Mermaid.js diagrams
- RAG Context: Compact schema for LLM prompts
- Column Profiling: Data quality and distribution analysis
For high-performance operations with large datasets:
- Bulk Insert: Handle thousands of records efficiently
- Bulk Update: Update multiple records with different conditions
- Bulk Delete: Delete multiple record sets in batches
Full ACID transaction support:
await mcp.call("begin_transaction", {});
await mcp.call("create_record", { table_name: "orders", data: {...} });
await mcp.call("update_record", { table_name: "inventory", data: {...} });
await mcp.call("commit_transaction", {});- Layer 1: Broad permission categories (list, read, create, etc.)
- Layer 2: Fine-grained tool category filtering
- Tool-level: Each tool requires specific permissions
- PII Masking: Automatic sensitive data redaction in exports
- Safe Exports:
safe_export_tablemasks emails, credit cards, passwords - Query Validation: Input validation and SQL injection prevention
- Environment Variables: Secure credential management
- Connection Testing: Validation before operations
- Error Handling: Comprehensive error reporting
Complete migration support with tracking:
// Initialize migration tracking
await mcp.call("init_migrations_table", {});
// Create migration
await mcp.call("create_migration", {
name: "add_user_avatar",
up_sql: "ALTER TABLE users ADD COLUMN avatar VARCHAR(255);",
down_sql: "ALTER TABLE users DROP COLUMN avatar;"
});
// Apply migrations
await mcp.call("apply_migrations", { dry_run: false });// Compare table structures
await mcp.call("compare_table_structure", {
table1: "users_old",
table2: "users_new"
});- Permission Denied: Check both permission layers in error messages
- Connection Failed: Verify database credentials and network
- Query Errors: Use
repair_queryfor diagnosis - Performance Issues: Use
analyze_queryand optimization hints
If your client reports MCP error -32000: Connection closed, the server process is usually crashing on startup.
If you see ReferenceError: exports is not defined in ES module scope in the server stderr logs, update to v1.33.2+ (fixes an ESM/CJS mismatch that caused the MCP process to exit immediately).
The system provides detailed error messages indicating:
- Which permission layer blocked access
- Required permissions vs current permissions
- Specific category requirements
- SQL syntax and logic errors
For detailed examples and advanced usage patterns, see the project README.md.