MySQL InnoDB Cluster – HowTo #2 – Validate an instance
How do I… Validate an instance for MySQL InnoDB Cluster usage?
Short answer
Use:
Long answer…
In this article I assuming you already know what is MySQL Group Replication & MySQL InnoDB Cluster.
Additionally you can read this tutorial and this article from my colleague lefred or this one on Windows Platform from my colleague Ivan.
During the cluster creation process or when you want to add a node to a running cluster, the chosen MySQL instance must be valid for an InnoDB Cluster usage.
That is, be compliant with Group Replication requirements.
MySQL Shell provide a simple and easy way to check if your instance is valid: checkInstanceConfiguration()
I’m using MySQL Shell 8.0.16:
$ mysqlsh
MySQL Shell 8.0.16
Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type '\help' or '\?' for help; '\quit' to exit.
MySQL JS>
In this scenario my cluster is not created yet. However the logic would have been the same for adding a node to a running cluster.
Ask for help
The built-in help is simply awesome!
MySQL JS> dba.help('checkInstanceConfiguration')
NAME
checkInstanceConfiguration - Validates an instance for MySQL InnoDB
Cluster usage.
SYNTAX
dba.checkInstanceConfiguration(instance[, options])
WHERE
instance: An instance definition.
options: Data for the operation.
RETURNS
A descriptive text of the operation result.
DESCRIPTION
This function reviews the instance configuration to identify if it is
valid for usage with group replication. Use this to check for possible
configuration issues on MySQL instances before creating a cluster with
them or adding them to an existing cluster.
The instance definition is the connection data for the instance.
For additional information on connection data use \? connection.
Only TCP/IP connections are allowed for this function.
The options dictionary may contain the following options:
- mycnfPath: Optional path to the MySQL configuration file for the
instance. Alias for verifyMyCnf
- verifyMyCnf: Optional path to the MySQL configuration file for the
instance. If this option is given, the configuration file will be
verified for the expected option values, in addition to the global
MySQL system variables.
- password: The password to get connected to the instance.
- interactive: boolean value used to disable the wizards in the command
execution, i.e. prompts are not provided to the user and confirmation
prompts are not shown.
The connection password may be contained on the instance definition,
however, it can be overwritten if it is specified on the options.
The returned descriptive text of the operation result indicates whether
the instance is valid for InnoDB Cluster usage or not. If not, a table
containing the following information is presented:
- Variable: the invalid configuration variable.
- Current Value: the current value for the invalid configuration
variable.
- Required Value: the required value for the configuration variable.
- Note: the action to be taken.
The note can be one of the following:
- Update the config file and update or restart the server variable.
- Update the config file and restart the server.
- Update the config file.
- Update the server variable.
- Restart the server.
EXCEPTIONS
ArgumentError in the following scenarios:
- If the instance parameter is empty.
- If the instance definition is invalid.
- If the instance definition is a connection dictionary but empty.
RuntimeError in the following scenarios:
- If the instance accounts are invalid.
- If the instance is offline.
- If the instance is already part of a Replication Group.
- If the instance is already part of an InnoDB Cluster.
- If the given the instance cannot be used for Group Replication.
Check Instance Configuration
In order to check a MySQL instance I must connect to that instance, either by connecting to that instance with MySQL Shell or by providing the connection data to the function:
MySQL JS> dba.checkInstanceConfiguration('root@172.20.0.11')
Validating MySQL instance at 172.20.0.11:3306 for use in an InnoDB cluster...
This instance reports its own address as mysql_node1
Checking whether existing tables comply with Group Replication requirements...
WARNING: The following tables do not have a Primary Key or equivalent column:
test.squares, test.people, test.animal
Group Replication requires tables to use InnoDB and have a PRIMARY KEY or PRIMARY KEY Equivalent (non-null unique key). Tables that do not follow these requirements will be readable but not updateable when used with Group Replication. If your applications make updates (INSERT, UPDATE or DELETE) to these tables, ensure they use the InnoDB storage engine and have a PRIMARY KEY or PRIMARY KEY Equivalent.
Checking instance configuration...
Some configuration options need to be fixed:
+--------------------------+---------------+----------------+--------------------------------------------------+
| Variable | Current Value | Required Value | Note |
+--------------------------+---------------+----------------+--------------------------------------------------+
| binlog_checksum | CRC32 | NONE | Update the server variable |
| enforce_gtid_consistency | OFF | ON | Update read-only variable and restart the server |
| gtid_mode | OFF | ON | Update read-only variable and restart the server |
| server_id | 1 | <unique ID> | Update read-only variable and restart the server |
+--------------------------+---------------+----------------+--------------------------------------------------+
Some variables need to be changed, but cannot be done dynamically on the server.
Please use the dba.configureInstance() command to repair these issues.
{
"config_errors": [
{
"action": "server_update",
"current": "CRC32",
"option": "binlog_checksum",
"required": "NONE"
},
{
"action": "restart",
"current": "OFF",
"option": "enforce_gtid_consistency",
"required": "ON"
},
{
"action": "restart",
"current": "OFF",
"option": "gtid_mode",
"required": "ON"
},
{
"action": "restart",
"current": "1",
"option": "server_id",
"required": "<unique ID>"
}
],
"status": "error"
}
The output depends on the instance current status.
In my case 3 tables do not meet the requirements because of lack of Primary key (or non-null unique key).
Also I need to set correctly 4 variables and I must restart the MySQL instance because of 3 of them.
Automation
It is not always convenient (or recommended) to do these kind of task manually.
MySQL Shell is built in regards to DevOps usage :
$ mysqlsh -e "dba.checkInstanceConfiguration('root@172.20.0.12')"
Validating MySQL instance at 172.20.0.12:3306 for use in an InnoDB cluster...
This instance reports its own address as mysql_node2
Checking whether existing tables comply with Group Replication requirements...
No incompatible tables detected
Checking instance configuration...
Some configuration options need to be fixed:
+--------------------------+---------------+----------------+--------------------------------------------------+
| Variable | Current Value | Required Value | Note |
+--------------------------+---------------+----------------+--------------------------------------------------+
| binlog_checksum | CRC32 | NONE | Update the server variable |
| enforce_gtid_consistency | OFF | ON | Update read-only variable and restart the server |
| gtid_mode | OFF | ON | Update read-only variable and restart the server |
| server_id | 1 | <unique ID> | Update read-only variable and restart the server |
+--------------------------+---------------+----------------+--------------------------------------------------+
Some variables need to be changed, but cannot be done dynamically on the server.
Please use the dba.configureInstance() command to repair these issues.
Or even more practical:
$ mysqlsh -- dba checkInstanceConfiguration --user=root --host=172.20.0.13
Validating MySQL instance at 172.20.0.13:3306 for use in an InnoDB cluster...
This instance reports its own address as mysql_node3
Checking whether existing tables comply with Group Replication requirements...
No incompatible tables detected
Checking instance configuration...
Some configuration options need to be fixed:
+--------------------------+---------------+----------------+--------------------------------------------------+
| Variable | Current Value | Required Value | Note |
+--------------------------+---------------+----------------+--------------------------------------------------+
| binlog_checksum | CRC32 | NONE | Update the server variable |
| enforce_gtid_consistency | OFF | ON | Update read-only variable and restart the server |
| gtid_mode | OFF | ON | Update read-only variable and restart the server |
| server_id | 1 | <unique ID> | Update read-only variable and restart the server |
+--------------------------+---------------+----------------+--------------------------------------------------+
Some variables need to be changed, but cannot be done dynamically on the server.
Please use the dba.configureInstance() command to repair these issues.
{
"config_errors": [
{
"action": "server_update",
"current": "CRC32",
"option": "binlog_checksum",
"required": "NONE"
},
{
"action": "restart",
"current": "OFF",
"option": "enforce_gtid_consistency",
"required": "ON"
},
{
"action": "restart",
"current": "OFF",
"option": "gtid_mode",
"required": "ON"
},
{
"action": "restart",
"current": "1",
"option": "server_id",
"required": "<unique ID>"
}
],
"status": "error"
}
An other option is to create a script and pass it to MySQL Shell.
A very simple (and naive) example could be:
$ cat /tmp/servers.js
dba.checkInstanceConfiguration('root@172.20.0.11');
dba.checkInstanceConfiguration('root@172.20.0.12');
dba.checkInstanceConfiguration('root@172.20.0.13');
then process the file:
$ mysqlsh -f /tmp/servers.js
Validating MySQL instance at 172.20.0.11:3306 for use in an InnoDB cluster...
This instance reports its own address as mysql_node1
Checking whether existing tables comply with Group Replication requirements...
No incompatible tables detected
Checking instance configuration...
Instance configuration is compatible with InnoDB cluster
The instance '172.20.0.11:3306' is valid for InnoDB cluster usage.
Validating MySQL instance at 172.20.0.12:3306 for use in an InnoDB cluster...
This instance reports its own address as mysql_node2
Checking whether existing tables comply with Group Replication requirements...
No incompatible tables detected
Checking instance configuration...
Instance configuration is compatible with InnoDB cluster
The instance '172.20.0.12:3306' is valid for InnoDB cluster usage.
Validating MySQL instance at 172.20.0.13:3306 for use in an InnoDB cluster...
This instance reports its own address as mysql_node3
Checking whether existing tables comply with Group Replication requirements...
No incompatible tables detected
Checking instance configuration...
Instance configuration is compatible with InnoDB cluster
The instance '172.20.0.13:3306' is valid for InnoDB cluster usage.
In the previous scenario all the MySQL instances was set properly before the check.
Note that all that has been done previously in Javascript can also be done in Python :
MySQL 172.20.0.11:33060+ JS> \py
Switching to Python mode...
MySQL 172.20.0.11:33060+ Py> dba.check_instance_configuration()
Validating MySQL instance at 172.20.0.11:3306 for use in an InnoDB cluster...
This instance reports its own address as mysql_node1
Checking whether existing tables comply with Group Replication requirements...
No incompatible tables detected
Checking instance configuration...
Instance configuration is compatible with InnoDB cluster
The instance '172.20.0.11:3306' is valid for InnoDB cluster usage.
{
"status": "ok"
}
$ mysqlsh root@172.20.0.11 --py -f check_servers.py
...
To summarize
Q: How do I validate an instance for MySQL InnoDB Cluster usage?
A: Use check_instance_configuration()
References
- checkInstanceConfiguration() method:
- Working with InnoDB Cluster
- Using dba.checkInstanceConfiguration()
- Tutoriel – Déployer MySQL 8.0 InnoDB Cluster (09-2019)
- MySQL InnoDB Cluster – HowTo #1 – Monitor your cluster
- MySQL InnoDB Cluster – HowTo #2 – Validate an instance
Thanks for using MySQL!
Watch my videos on my YouTube channel and subscribe.
Thanks for using HeatWave & MySQL!
Cloud Solutions Architect at Oracle
MySQL Geek, author, blogger and speaker
I’m an insatiable hunger of learning.
—–
Blog: www.dasini.net/blog/en/
Twitter: https://twitter.com/freshdaz
SlideShare: www.slideshare.net/freshdaz
Youtube: https://www.youtube.com/channel/UC12TulyJsJZHoCmby3Nm3WQ
—–
[…] MySQL InnoDB Cluster – HowTo #2 – Validate an instance […]