You have seen in this previous post, that since 8.0.17, it’s now possible to query the MySQL Router using its REST API.
Additionally, we also saw in this post, that since 8.0.17, we are now able to write extensions to MySQL Shell using the Extension Framework.
Let’s combine both and see how we can integrate the MySQL Router’s REST API in the Shell.
I’ve created an extension in
ext.router that creates a MySQL Router Object.
The new extension, as a method to create the object:
This is an example that illustrates how to create a MySQL Router Object, as you can see you can pass the password directly as parameter but it’s not recommended in interactive mode. It’s recommended the enter it at the prompt:
Now that the object is created, you can see that it has two available methods:
status() method, we can get information about a MySQL Router.
Let’s see it in action:
In this example above, we can see that the router is connected to a cluster called myCluster.
The 4 routes are configured and they are all active. We can see some statistics and more interesting, the final destinations for each routes.
The second method is
We can see it in action below:
This method returns all the connections that are made to the MySQL Router for each routes (or some if specified) and what it’s the final destination. It also shows some traffic statistics.
This is another great example on how to use together some of the new features that the MySQL teams released in MySQL 8.0.17.
This extension is a bit more complicated as it creates an object that we can use with its methods.
The code is currently available in this branch on github.
There are infinite possibilities to extend the MySQL Shell. Don’t hesitate to share your ideas and contributions !