Documentation Home
MySQL Shell for VS Code


MySQL Shell for VS Code  /  MySQL Shell Consoles  /  MySQL Shell, MySQL Router, and InnoDB Cluster

Pre-General Availability: 2024-05-02

5.9 MySQL Shell, MySQL Router, and InnoDB Cluster

MySQL Router is a building block for high availability (HA) solutions. It simplifies application development by intelligently routing connections to MySQL servers for increased performance and reliability.

MySQL Router is part of InnoDB Cluster and is lightweight middleware that provides transparent routing between your application and back-end MySQL servers. It is used for a wide variety of use cases, such as providing high availability and scalability by routing database traffic to appropriate back-end MySQL servers. The pluggable architecture also enables developers to extend MySQL Router for custom use cases.

MySQL Group Replication replicates databases across multiple servers while performing automatic failover in the event of a server failure. When used with a InnoDB Cluster, MySQL Router acts as a proxy to hide the multiple MySQL instances on your network and map the data requests to one of the cluster instances. As long as there are enough online replicas and communication between the components is intact, applications are able to contact one of them. MySQL Router also makes this possible by having applications connect to MySQL Router instead of directly to MySQL.

Testing MySQL Router configurations

When you have set up an InnoDB Cluster and have MySQL Router running, you can test the InnoDB Cluster and MySQL Router setup using MySQL Shell Consoles.

By default, InnoDB Cluster can be reached by connecting to:

  • classic MySQL protocol

    • Read/Write Connections: instance-address: port 6446

    • Read/Only Connections: instance-address: port 6447

  • X Protocol

    • Read/Write Connections: instance-address: port 6448

    • Read/Only Connections: instance-address: port 6449

Instead of connecting to one of the MySQL server instances directly, connect through the MySQL Router.

  1. Issue the following connection command, where the user is demo-user and the address of the instance is demo-instance, and classic MySQL protocol is being used:

    shell.connect ('demo-user@demo-instance:6446')
  2. Provide the root password to connect to the InnoDB Cluster.

  3. Check the status of the InnoDB Cluster by creating a variable cluster and assigning it with the value of the dba.getCluster() JavaScript method:

    cluster = dba.getCluster()
    cluster.status()
  4. Switch to SQL mode:

    \sql
  5. Query the port the instance is running on, by issuing:

    SELECT @@port; 
    +--------+
    | @@port |
    +--------+
    |   3310 |
    +--------+
    1 row in set (0.0007 sec)

    In this example, InnoDB Cluster is running on port 3310, so MySQL Router has been configured correctly and is running successfully.