Skip to content

MySQL Router

Chris edited this page Jul 7, 2026 · 100 revisions

MySQL Router

Tools

Resources

Prompts
OAuth 2.1

Code Mode

💎 Enterprise-Grade Value Proposition

  • Maximize AI Context Windows: Transform complex database workflows via Code Mode, unlocking up to 90% token efficiency.
  • Accelerate Agent Deployments: Build autonomous AI integrations instantly with zero-trust telemetry and strict boundaries.
  • Unleash Autonomous Operations: Equip intelligent agents with granular, schema-enforced database capabilities.
  • Scale Without Bottlenecks: Sustain high-throughput agent swarms with robust, enterprise-grade connection pooling.
  • Secure Every Transaction: Fortify your infrastructure with native OAuth 2.1 authentication and sandboxed execution.

Check Prerequisites

  • MySQL Router 8.0.17+ with REST API enabled
  • Router REST API credentials (username/password)
  • Network access to Router REST API endpoint (default: HTTPS on port 8443)
  • For InnoDB Cluster mode: The cluster must be running for REST API authentication

Important:

Router REST API typically authenticates against the InnoDB Cluster. Authentication fails with 401 errors if the cluster is down.

Browse Available Tools

Tool Description Parameters
mysql_router_status Get Router process status and version summary, limit, compact
mysql_router_routes List all configured routes summary, limit, compact
mysql_router_route_status Get status of a specific route routeName, summary, limit, compact
mysql_router_route_health Check health/liveness of a route routeName, summary, limit, compact
mysql_router_route_connections List active connections on route routeName, summary, limit, compact
mysql_router_route_destinations List backend MySQL server destinations routeName, summary, limit, compact
mysql_router_route_blocked_hosts List blocked IP addresses for a route routeName, summary, limit, compact
mysql_router_metadata_status InnoDB Cluster metadata cache status ⚠️ metadataName, summary, limit, compact
mysql_router_pool_status Connection pool statistics poolName, summary, limit, compact

⚠️ = Requires InnoDB Cluster (Note: mysql_router_pool_status requires router connection pool configuration, not an InnoDB Cluster) 💡 = All Router tools support token-optimized payloads via optional summary, limit, and compact flags.

Configure Authentication

Authenticate via InnoDB Cluster (Recommended)

Bootstrapping Router against an InnoDB Cluster uses metadata_cache authentication. This authenticates API users against the metadata database.

1. Create REST API user in the cluster:

-- Connect to any cluster node
-- The user will be stored in mysql_innodb_cluster_metadata.router_rest_accounts
# Use mysqlrouter_passwd to generate the password hash
mysqlrouter_passwd set /tmp/rest_api.pwd rest_api
# Insert into cluster metadata (on PRIMARY node)
mysql -h localhost -P 3307 -u cluster_admin -p -e "INSERT INTO mysql_innodb_cluster_metadata.router_rest_accounts(cluster_id, user, authentication_method, authentication_string, description) SELECT cluster_id, 'rest_api', 'modular_crypt_format', '<hash_from_mysqlrouter_passwd>', 'REST API user' FROM mysql_innodb_cluster_metadata.clusters LIMIT 1;"

2. Router config uses metadata_cache backend:

[http_auth_backend:default_auth_backend]
backend=metadata_cache

Authenticate via File (Standalone)

For standalone Router deployments without InnoDB Cluster:

[http_server]
port=8443
ssl=1
ssl_cert=/path/to/router-cert.pem
ssl_key=/path/to/router-key.pem

[http_auth_realm:default_auth_realm]
backend=default_auth_backend
method=basic
name=default_realm

[http_auth_backend:default_auth_backend]
backend=file
filename=/path/to/mysqlrouter.pwd

[rest_router]
require_realm=default_auth_realm

[rest_routing]
require_realm=default_auth_realm
# Generate password hash (prompts for password)
mysqlrouter_passwd set /path/to/mysqlrouter.pwd router_admin

Secure with OAuth 2.1

Secure MySQL Router operations using OAuth 2.1 validation. See the OAuth page for setup instructions.


Configure Your Environment

Variable Default Description
MYSQL_ROUTER_URL https://localhost:8443 Router REST API base URL
MYSQL_ROUTER_USER - Router API username
MYSQL_ROUTER_PASSWORD - Router API password
MYSQL_ROUTER_API_VERSION /api/20190715 API version path
MYSQL_ROUTER_INSECURE false Skip TLS verification (for self-signed certs)

⚠️ Never commit Router credentials to version control. Use environment variables or secure secrets management.


Integrate the Server

{
  "mcpServers": {
    "mysql-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@neverinfamous/mysql-mcp",
        "--transport",
        "stdio",
        "--mysql",
        "mysql://user:password@localhost:3306/database"
      ],
      "env": {
        "MYSQL_ROUTER_URL": "https://router.example.com:8443",
        "MYSQL_ROUTER_USER": "router_admin",
        "MYSQL_ROUTER_PASSWORD": "router_password",
        "MYSQL_ROUTER_INSECURE": "true"
      }
    }
  }
}

Isolate Your Workloads

If you only want Router tools (e.g., for a dedicated monitoring agent):

{
  "args": [
    "--transport",
    "stdio",
    "--tool-filter",
    "router"
  ]
}

This exposes only the Router management tools.

Troubleshoot Issues

Resolve "fetch failed" Error

Cause: Router REST API is unreachable or TLS handshake failed.

Solutions:

  1. Verify Router is running: docker ps | grep router
  2. Check Router logs: docker logs mysql-router
  3. Test API manually: curl -k -u rest_api:router_api https://localhost:8443/api/20190715/router/status
  4. Ensure MYSQL_ROUTER_INSECURE=true is set for self-signed certificates

Resolve 401 Unauthorized Error

Cause: Authentication failed. This usually means the InnoDB Cluster is not running.

Solutions:

  1. Start the InnoDB Cluster: docker compose -f innodb-cluster.yml up -d
  2. Reboot cluster from outage if needed: dba.rebootClusterFromCompleteOutage()
  3. Restart Router to reconnect: docker restart mysql-router
  4. Verify credentials match the router_rest_accounts table

Resolve GR Member Error

Cause: Cluster nodes are running but Group Replication is not active.

Solution: Reboot cluster from complete outage using MySQL Shell:

mysqlsh --uri cluster_admin:password@localhost:3307 --js \
  -e "dba.rebootClusterFromCompleteOutage('clusterName', {force: true})"

Resolve 404 Not Found

Cause: The connection pool name doesn't exist or connection pooling is disabled.

Solution: This is expected if Router lacks connection pooling configuration. The tool works correctly.

Review Version History

v3.2.2 Updates

  • Enterprise Security: Implemented OAuth 2.1 validator middleware for secure API integrations.
  • Token Optimization: Added optional flags across tools for reduced token usage.

v3.0.2 Changes

  • Graceful error handling — All errors extend MySQLMcpError and return an enriched ErrorResponse. We secure error payloads with Zod 4 boundaries. This ensures Standard Schema compliance for predictable parsing.
  • mysql_router_pool_status — Fixed description to reflect API response fields (idleServerConnections, stashedServerConnections).

Explore Related Topics

MySQL MCP Documentation

Value Proposition Enforce strict execution boundaries and maximize LLM context efficiency for secure, autonomous database interactions. Read the full value proposition

🏠 Home


Launch Your Setup


Connect Ecosystem Tools


Security & Compliance


Scale Your Operations


Explore External Links

Clone this wiki locally