Definition of MySQL InnoDB Cluster
MySQL InnoDB Cluster can be said as a completely great availability resolution delivered by MySQL which consists of only one and multiple master abilities and failover recognition. Here, by implementing the AdminAPI comprised of MySQL Shell, one can organize and administer a set of a minimum of three instances of MySQL server to purpose as an InnoDB Cluster easily. MySQL InnoDB Cluster includes three modules as follows:
- MySQL Group Replication – A collection of the database server that duplicates each other having fault tolerance.
- MySQL Router – Inquiry router to the vigorous database nodes.
- MySQL Shell – As a client, helper, and configuration tool.
MySQL InnoDB cluster is performed using AdminAPI contained in the MySQL Shell for providing a great availability solution by grouping instances of MySQL servers at least three. Every instance of MySQL server executes MySQL group Replication.
The AdminAPI in MySQL Shell is accessed using a global variable dba with its related methods. This procedure of the dba variable allows a user to configure, deploy, and administer the InnoDB clusters. Here, suppose we will use the method dba.createCluster(), for creating an InnoDB cluster.
Note that MySQL Shell permits to connect to the servers using a socket connection. Whereas AdminAPI needs TCP connections to an instance of the server. So, we should not use socket connections while using AdminAPI. You can use the command dba.help() method to get online help for AdminAPI.
For online support on a particular approach, we need to apply a format object.help(‘methodname’), explained in the below illustration:
dba.help(‘getClsuter’) // Fetches a cluster from metadata store
Name defines the parameter to state the name of the cluster to be resumed.
If the name is not detailed, it will return the default cluster.
But if the name is stated and no cluster with the defined name is found then, it will raise an error.
How InnoDB Cluster works in MySQL?
MySQL is an object-relational and an open-source type of database management system available with certain more features like scalable and extensible. It also maintains data replication through multiple data centers.
MySQL 5.7 version supports MySQL InnoDB Cluster which is an Oracle high accessibility solution and can be installed over MySQL for holding multiple master abilities and spontaneous failover. This solution comprises three constituents:
1. Group Replication
It defines a collection of database servers where MySQL databases are replicated through multiple nodes including the fault tolerance feature. Suppose if any alterations in the data happen in the MySQL databases, then it routinely duplicates to the secondary nodes of the server. This idea of Group Replication in MySQL is identical to the concept of the AlwaysOn availability group.
2. MySQL Router
This is helpful to make client applications aware of the cluster topology along with the PRIMARY instance whenever a failover happens. MySQL Router regulates this type of functionality by routing where the data requests are redirected to the accessible MySQL server instance. It works as a proxy that is implemented to hide the multiple MySQL database servers. This concept is identical to the Virtual Network name concept of the Windows Server failover cluster.
3. MySQL Shell
This is a kind of tool used for configuration to implement connect, deploy as well as manage the MySQL InnoDB cluster. MySQL Shell consists of an Admin API which has a dba global variable in order to deploy and accomplish the InnoDB Cluster.
Let us discuss a few other features which are delivered with the help of this solution as follows:
1. Distinct Primary or Multiple Primary Modes
It means that the cluster can control either with only a writer and more than one reader which is also default setup and recommended one or with more than one writer where entire nodes are able to admit write transactions. Due to the conflict firmness, the latter one is provided at a cost of a performance penalty.
2. Spontaneous Failure Recognition
Here, an internal component is capable of detecting a failed node which can be either a crash or any network problems, and also agrees to eliminate it from the cluster mechanically. Suppose if a member does not connect with the cluster and also gets inaccessible then, it will not receive transactions. This assures that the cluster data has not been obstructed by this type of situation.
3. Fault Tolerance
It defines the strategy which the cluster implements to maintain failing members. Since it is also based on the majority kept by the other two members where a cluster requires three members for supporting one node. If there is a larger number of nodes then, there will also be a larger number of failing nodes which is supported by the cluster. In a cluster, the extreme number of members or nodes is presently restricted to 7 where the majority is stored by either four or more active nodes. We can say that a cluster of seven will support and maintain up to three failing nodes.
Let us view about working with MySQL InnoDB Cluster and regulating shared administration tasks explained as follows:
1. Eliminating Instances from the MySQL InnoDB Cluster
When you want to remove the instances at any time from a cluster then, you can do so. This can be performed using a method of the cluster.removeInstance (instance) written as:
This method operation assures that the specific instance is eliminated from the metadata of entire cluster members that are ONLINE as well as the instance itself. If there are any transactions needed to be applied by the instance being eliminated the AdminAPI will wait for a few seconds as configured by MySQL Shell with dba.gtidWaitTimeout option whose default value is the 60s.
2. Running an InnoDB Cluster
If a user wants to run a cluster you require to connect to a read-write instance such as the Primary in only one primary cluster using the command cluster.dissolve(). This will remove whole metadata along with configuration linked with the cluster and restricts Group Replication on the instances. Whereas any data duplicated between the instances are not detached.
You will find no way to undo this process of dissolving or running an InnoDB cluster but it can be created again using the command:
The cluster.dissolve() method will only configure instances of a server which are ONLINE or reachable
3. Altering a Clusters’ Topology
An InnoDB cluster executes in a single primary mode by default. Here, the cluster consists of only one primary server which takes read and write (R/W) queries and the remaining instances in the cluster take only read(R/O) queries. For this, the operational command is:
But when the cluster is to be configured in multi-primary mode to run then, all instances in the cluster are defined to be primaries where they take both read and write(R/W) queries. For this, we will use the command as:
Since MySQL Innodb is recognized as a storage engine responsible for the database management system MySQL and MariaDB, therefore MySQL InnoDB Cluster has been introduced in MySQL to be a high availability solution to configure and administer a set of a minimum of three instances of MySQL servers easily that works as an InnoDB cluster. But the InnoDB cluster does not deliver support or maintenance for the MySQL NDB cluster as this NDB cluster is governed by the NDB storage engine and also a number of code programs particular to the NDB cluster not equipped with MySQL server version 8.0.
This is a guide to MySQL InnoDB Cluster. Here we discuss the definition, features, and How InnoDB cluster works in MySQL? along with examples respectively. You may also have a look at the following articles to learn more –