MySQL Shell API 9.0.1
Unified development interface for MySQL Products
|
InnoDB Cluster, ReplicaSet, and ClusterSet management functions. More...
Methods | |
JSON | checkInstanceConfiguration (InstanceDef instance, Dictionary options) |
Validates an instance for MySQL InnoDB Cluster usage. More... | |
Undefined | configureReplicaSetInstance (InstanceDef instance, Dictionary options) |
Validates and configures an instance for use in an InnoDB ReplicaSet. More... | |
Undefined | configureInstance (InstanceDef instance, Dictionary options) |
Validates and configures an instance for MySQL InnoDB Cluster usage. More... | |
Cluster | createCluster (String name, Dictionary options) |
Creates a MySQL InnoDB Cluster. More... | |
ReplicaSet | createReplicaSet (String name, Dictionary options) |
Creates a MySQL InnoDB ReplicaSet. More... | |
Undefined | deleteSandboxInstance (Integer port, Dictionary options) |
Deletes an existing MySQL Server instance on localhost. More... | |
Instance | deploySandboxInstance (Integer port, Dictionary options) |
Creates a new MySQL Server instance on localhost. More... | |
Undefined | dropMetadataSchema (Dictionary options) |
Drops the Metadata Schema. More... | |
Cluster | getCluster (String name) |
Returns an object representing a Cluster. More... | |
ClusterSet | getClusterSet () |
Returns an object representing a ClusterSet. More... | |
ReplicaSet | getReplicaSet () |
Returns an object representing a ReplicaSet. More... | |
Undefined | killSandboxInstance (Integer port, Dictionary options) |
Kills a running MySQL Server instance on localhost. More... | |
Cluster | rebootClusterFromCompleteOutage (String clusterName, Dictionary options) |
Brings a cluster back ONLINE when all members are OFFLINE. More... | |
Undefined | startSandboxInstance (Integer port, Dictionary options) |
Starts an existing MySQL Server instance on localhost. More... | |
Undefined | stopSandboxInstance (Integer port, Dictionary options) |
Stops a running MySQL Server instance on localhost. More... | |
Undefined | upgradeMetadata (Dictionary options) |
Upgrades (or restores) the metadata to the version supported by the Shell. More... | |
Properties | |
Integer | verbose |
Controls debug message verbosity for sandbox related dba operations. More... | |
Session | session |
The session the dba object will use by default. More... | |
InnoDB Cluster, ReplicaSet, and ClusterSet management functions.
JSON checkInstanceConfiguration | ( | InstanceDef | instance, |
Dictionary | options | ||
) |
Validates an instance for MySQL InnoDB Cluster usage.
instance | An instance definition. |
options | Optional data for the operation. |
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 about MySQL connection data, see Connection Data.
The options dictionary may contain the following 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:
The note can be one of the following:
Undefined configureReplicaSetInstance | ( | InstanceDef | instance, |
Dictionary | options | ||
) |
Validates and configures an instance for use in an InnoDB ReplicaSet.
instance | Optional An instance definition. By default, the active shell session is used. |
options | Optional Additional options for the operation. |
This function will verify and automatically configure the target instance for use in an InnoDB ReplicaSet.
The function can optionally create a "cluster administrator" account, if the "clusterAdmin" and "clusterAdminPassword" options are given. The account is created with the minimal set of privileges required to manage InnoDB clusters or ReplicaSets. The "cluster administrator" account must have matching username and password across all instances of the same cluster or replicaset.
The instance definition is the connection data for the instance.
For additional information about MySQL connection data, see Connection Data.
The options dictionary may contain the following options:
This function reviews the instance configuration to identify if it is valid for usage in replicasets. An exception is thrown if not.
If the instance was not valid for InnoDB ReplicaSet and interaction is enabled, before configuring the instance a prompt to confirm the changes is presented and a table with the following information:
Undefined configureInstance | ( | InstanceDef | instance, |
Dictionary | options | ||
) |
Validates and configures an instance for MySQL InnoDB Cluster usage.
instance | Optional An instance definition. |
options | Optional Additional options for the operation. |
This function auto-configures the instance for InnoDB Cluster usage. If the target instance already belongs to an InnoDB Cluster it errors out.
The instance definition is the connection data for the instance.
For additional information about MySQL connection data, see Connection Data.
The options dictionary may contain the following options:
If the outputMycnfPath option is used, only that file is updated and mycnfPath is treated as read-only.
The clusterAdmin must be a standard MySQL account name. It could be either an existing account or an account to be created.
The clusterAdminPassword must be specified only if the clusterAdmin account will be created.
This function reviews the instance configuration to identify if it is valid for usage in group replication and cluster. An exception is thrown if not.
If the instance was not valid for InnoDB Cluster and interaction is enabled, before configuring the instance a prompt to confirm the changes is presented and a table with the following information:
Cluster createCluster | ( | String | name, |
Dictionary | options | ||
) |
Creates a MySQL InnoDB Cluster.
name | An identifier for the Cluster to be created. |
options | Optional dictionary with additional parameters described below. |
Creates a MySQL InnoDB Cluster taking as seed instance the server the shell is currently connected to.
The options dictionary can contain the following values:
An InnoDB Cluster may be setup in two ways:
Note that Multi-Primary mode has limitations about what can be safely executed. Make sure to read the MySQL documentation for Group Replication and be aware of what is and is not safely executable in such setups.
By default this function creates a Single Primary Cluster. Use the multiPrimary option set to true if a Multi Primary Cluster is required.
The Cluster's name must be non-empty and no greater than 63 characters long. It can only start with an alphanumeric character or with _ (underscore), and can only contain alphanumeric, _ ( underscore), . (period), or - (hyphen) characters.
disableClone should be set to true if built-in clone support should be completely disabled, even in instances where that is supported. Built-in clone support is available starting with MySQL 8.0.17 and allows automatically provisioning new Cluster members by copying state from an existing Cluster member. Note that clone will completely delete all data in the instance being added to the Cluster.
gtidSetIsComplete is used to indicate that GTIDs have been always enabled at the Cluster seed instance and that GTID_EXECUTED contains all transactions ever executed. It must be left as false if data was inserted or modified while GTIDs were disabled or if RESET MASTER was executed. This flag affects how Cluster.addInstance() decides which recovery methods are safe to use. Distributed recovery based on replaying the transaction history is only assumed to be safe if the transaction history is known to be complete, otherwise Cluster members could end up with incomplete data sets.
adoptFromGR allows creating an InnoDB Cluster from an existing unmanaged Group Replication setup, enabling use of MySQL Router and the shell AdminAPI for managing it.
The memberSslMode option controls whether TLS is to be used for connections opened by Group Replication from one server to another (both recovery and group communication, in either communication stack). It also controls what kind of verification the client end of connections perform on the SSL certificate presented by the server end.
The memberSslMode option supports the following values:
If memberSslMode is not specified AUTO will be used by default.
The memberAuthType option supports the following values:
If memberAuthType is not specified, "PASSWORD" will be used by default.
When CERT_ISSUER or CERT_SUBJECT are used, the server's own certificate is used as its client certificate when authenticating replication channels with peer servers. memberSslMode must be at least REQUIRED, although VERIFY_CA or VERIFY_IDENTITY are recommended for additional security.
The ipAllowlist format is a comma separated list of IP addresses or subnet CIDR notation, for example: 192.168.1.0/24,10.0.0.1. By default the value is set to AUTOMATIC, allowing addresses from the instance private network to be automatically set for the allowlist.
This option is only used and allowed when communicationStack is set to XCOM.
The groupName and localAddress are advanced options and their usage is discouraged since incorrect values can lead to Group Replication errors.
The value for groupName is used to set the Group Replication system variable 'group_replication_group_name'.
The value for localAddress is used to set the Group Replication system variable 'group_replication_local_address'. The localAddress option accepts values in the format: 'host:port' or 'host:' or ':port'. If the specified value does not include a colon (:) and it is numeric, then it is assumed to be the port, otherwise it is considered to be the host. When the host is not specified, the default value is the value of the system variable 'report_host' if defined (i.e., not 'NULL'), otherwise it is the hostname value. When the port is not specified, the default value is the port of the target instance if the communication stack in use by the Cluster is 'MYSQL', otherwise, port * 10 + 1 when the communication stack is 'XCOM'. In case the automatically determined default port value is invalid (> 65535) then an error is thrown.
The exitStateAction option supports the following values:
If exitStateAction is not specified, it defaults to OFFLINE_MODE for server versions 8.4.0 or newer, and READ_ONLY otherwise.
The consistency option supports the following values:
If consistency is not specified, it defaults to BEFORE_ON_PRIMARY_FAILOVER for server versions 8.4.0 or newer, and EVENTUAL otherwise.
The value for exitStateAction is used to configure how Group Replication behaves when a server instance leaves the group unintentionally (for example after encountering an applier error) or exhausts its auto-rejoin attempts. When set to ABORT_SERVER, the instance shuts itself down. When set to READ_ONLY the server switches itself to super-read-only mode. When set to OFFLINE_MODE it switches itself to offline mode. In this mode, connected client users are disconnected on their next request and connections are no longer accepted, with the exception of client users that have the CONNECTION_ADMIN or SUPER privilege. The exitStateAction option accepts case-insensitive string values, being the accepted values: OFFLINE_MODE (or 2), ABORT_SERVER (or 1) and READ_ONLY (or 0).
The default value is OFFLINE_MODE for server versions 8.4.0 or newer, and READ_ONLY otherwise.
The value for memberWeight is used to set the Group Replication system variable 'group_replication_member_weight'. The memberWeight option accepts integer values. Group Replication limits the value range from 0 to 100, automatically adjusting it if a lower/bigger value is provided.
Group Replication uses a default value of 50 if no value is provided.
The value for consistency is used to set the Group Replication system variable 'group_replication_consistency' and configure the transaction consistency guarantee which a cluster provides.
When set to BEFORE_ON_PRIMARY_FAILOVER, whenever a primary failover happens in single-primary mode (default), new queries (read or write) to the newly elected primary that is applying backlog from the old primary, will be hold before execution until the backlog is applied. Special care is needed if LOCK / UNLOCK queries are used in a secondary, because the UNLOCK statement can be held. This means that, if the secondary is promoted, and transactions from the primary are being applied that target locked tables, they won't be applied and an explicit UNLOCK will also hold because the secondary needs to finish applying the transactions from the previous primary. See https://dev.mysql.com/doc/refman/en/group-replication-system-variables.html#sysvar_group_replication_consistency for more details.
When set to EVENTUAL, read queries to the new primary are allowed even if the backlog isn't applied but writes will fail (if the backlog isn't applied) due to super-read-only mode being enabled. The client may return old values.
When set to BEFORE, each transaction (RW or RO) waits until all preceding transactions are complete before starting its execution. This ensures that each transaction is executed on the most up-to-date snapshot of the data, regardless of which member it is executed on. The latency of the transaction is affected but the overhead of synchronization on RW transactions is reduced since synchronization is used only on RO transactions.
When set to AFTER, each RW transaction waits until its changes have been applied on all of the other members. This ensures that once this transaction completes, all following transactions read a database state that includes its changes, regardless of which member they are executed on. This mode shall only be used on a group that is used for predominantly RO operations to ensure that subsequent reads fetch the latest data which includes the latest writes. The overhead of synchronization on every RO transaction is reduced since synchronization is used only on RW transactions.
When set to BEFORE_AND_AFTER, each RW transaction waits for all preceding transactions to complete before being applied and until its changes have been applied on other members. A RO transaction waits for all preceding transactions to complete before execution takes place. This ensures the guarantees given by BEFORE and by AFTER. The overhead of synchronization is higher.
The consistency option accepts case-insensitive string values, being the accepted values: EVENTUAL (or 0), BEFORE_ON_PRIMARY_FAILOVER (or 1), BEFORE (or 2), AFTER (or 3), and BEFORE_AND_AFTER (or 4).
It defaults to BEFORE_ON_PRIMARY_FAILOVER for server versions 8.4.0 or newer, and EVENTUAL otherwise.
The value for expelTimeout is used to set the Group Replication system variable 'group_replication_member_expel_timeout' and configure how long Group Replication will wait before expelling from the group any members suspected of having failed. On slow networks, or when there are expected machine slowdowns, increase the value of this option. The expelTimeout option accepts positive integer values and, since 8.0.21, defaults to 5 seconds.
The value for autoRejoinTries is used to set the Group Replication system variable 'group_replication_autorejoin_tries' and configure how many times an instance will try to rejoin a Group Replication group after being expelled. In scenarios where network glitches happen but recover quickly, setting this option prevents users from having to manually add the expelled node back to the group. The autoRejoinTries option accepts positive integer values and, since 8.0.21, defaults to 3.
The value for communicationStack is used to choose which Group Replication communication stack must be used in the Cluster. It's used to set the value of the Group Replication system variable 'group_replication_communication_stack'.
When set to legacy 'XCom', all internal GCS network traffic (PAXOS and communication infrastructure) flows through a separate network address: the localAddress.
When set to 'MySQL', such traffic re-uses the existing MySQL Server facilities to establish connections among Cluster members. It allows a simpler and safer setup as it obsoletes the usage of IP allowlists (ipAllowlist), removes the explicit need to have a separate network address (localAddress), and introduces user-based authentication.
The default value for Clusters running 8.0.27+ is 'MySQL'.
The value for transactionSizeLimit is used to set the Group Replication system variable 'group_replication_transaction_size_limit' and configures the maximum transaction size in bytes which the Cluster accepts. Transactions larger than this size are rolled back by the receiving member and are not broadcast to the Cluster.
The transactionSizeLimit option accepts positive integer values and, if set to zero, there is no limit to the size of transactions the Cluster accepts
All members added or rejoined to the Cluster will use the same value.
The value for paxosSingleLeader is used to enable or disable the Group Communication engine to operate with a single consensus leader when the Cluster is in single-primary more. When enabled, the Cluster uses a single leader to drive consensus which improves performance and resilience in single-primary mode, particularly when some of the Cluster's members are unreachable.
The option is available on MySQL 8.0.31 or newer and the default value is 'OFF'.
ReplicaSet createReplicaSet | ( | String | name, |
Dictionary | options | ||
) |
Creates a MySQL InnoDB ReplicaSet.
name | An identifier for the ReplicaSet to be created. |
options | Optional dictionary with additional parameters described below. |
This function will create a managed ReplicaSet using MySQL asynchronous replication, as opposed to Group Replication. The MySQL instance the shell is connected to will be the initial PRIMARY of the ReplicaSet. The replication channel will have TLS encryption enabled by default.
The function will perform several checks to ensure the instance state and configuration are compatible with a managed ReplicaSet and if so, a metadata schema will be initialized there.
New replica instances can be added through the addInstance() function of the returned ReplicaSet object. Status of the instances and their replication channels can be inspected with status().
InnoDB ReplicaSets
A ReplicaSet allows managing a GTID-based MySQL replication setup, in a single PRIMARY/multiple SECONDARY topology.
A ReplicaSet has several limitations compared to a InnoDB cluster and thus, it is recommended that InnoDB clusters be preferred unless not possible. Generally, a ReplicaSet on its own does not provide High Availability. Among its limitations are:
Pre-Requisites
The following is a non-exhaustive list of requirements for managed ReplicaSets. The dba.configureInstance() command can be used to make necessary configuration changes automatically.
The ReplicaSet's name must be non-empty and no greater than 63 characters long. It can only start with an alphanumeric character or with _ (underscore), and can only contain alphanumeric, _ ( underscore), . (period), or - ( hyphen) characters.
Adopting an Existing Topology
Existing asynchronous setups can be managed by calling this function with the adoptFromAR option. The topology will be automatically scanned and validated, starting from the instance the shell is connected to, and all instances that are part of the topology will be automatically added to the ReplicaSet.
The only changes made by this function to an adopted ReplicaSet are the creation of the metadata schema. Existing replication channels will not be changed during adoption, although they will be changed during PRIMARY switch operations.
However, it is only possible to manage setups that use supported configurations and topology. Configuration of all instances will be checked during adoption, to ensure they are compatible. All replication channels must be active and their transaction sets as verified through GTID sets must be consistent. The data set of all instances are expected to be identical, but is not verified.
The options dictionary can contain the following values:
The replicationSslMode option supports the following values:
If replicationSslMode is not specified AUTO will be used by default.
The memberAuthType option supports the following values:
If memberAuthType is not specified, "PASSWORD" will be used by default.
When CERT_ISSUER or CERT_SUBJECT are used, the server's own certificate is used as its client certificate when authenticating replication channels with peer servers. replicationSslMode must be at least REQUIRED, although VERIFY_CA or VERIFY_IDENTITY are recommended for additional security.
Undefined deleteSandboxInstance | ( | Integer | port, |
Dictionary | options | ||
) |
Deletes an existing MySQL Server instance on localhost.
port | The port of the instance to be deleted. |
options | Optional dictionary with options that modify the way this function is executed. |
This function will delete an existing MySQL Server instance on the local host. The following options affect the result:
The sandboxDir must be the one where the MySQL instance was deployed. If not specified it will use:
~/mysql-sandboxes on Unix-like systems or %userprofile%\MySQL\mysql-sandboxes on Windows systems.
If the instance is not located on the used path an error will occur.
Instance deploySandboxInstance | ( | Integer | port, |
Dictionary | options | ||
) |
Creates a new MySQL Server instance on localhost.
port | The port where the new instance will listen for connections. |
options | Optional dictionary with options affecting the new deployed instance. |
This function will deploy a new MySQL Server instance, the result may be affected by the provided options:
If the portx option is not specified, it will be automatically calculated as 10 times the value of the provided MySQL port.
The password option specifies the MySQL root password on the new instance.
The sandboxDir must be an existing folder where the new instance will be deployed. If not specified the new instance will be deployed at:
~/mysql-sandboxes on Unix-like systems or %userprofile%\MySQL\mysql-sandboxes on Windows systems.
SSL support is added by default if not already available for the new instance, but if it fails to be added then the error is ignored. Set the ignoreSslError option to false to ensure the new instance is deployed with SSL support.
Undefined dropMetadataSchema | ( | Dictionary | options | ) |
Drops the Metadata Schema.
options | Dictionary containing an option to confirm the drop operation. |
The options dictionary may contain the following options:
Cluster getCluster | ( | String | name | ) |
ClusterSet getClusterSet | ( | ) |
Returns an object representing a ClusterSet.
The returned object is identical to the one returned by createClusterSet() and can be used to manage the ClusterSet.
The function will work regardless of whether the active session is established to an instance that belongs to a PRIMARY or a REPLICA Cluster, but its copy of the metadata is expected to be up-to-date.
This function will also work if the PRIMARY Cluster is unreachable or unavailable, although ClusterSet change operations will not be possible, except for failover with forcePrimaryCluster().
ReplicaSet getReplicaSet | ( | ) |
Returns an object representing a ReplicaSet.
The returned object is identical to the one returned by createReplicaSet() and can be used to manage the replicaset.
The function will work regardless of whether the target instance is a PRIMARY or a SECONDARY, but its copy of the metadata is expected to be up-to-date. This function will also work if the PRIMARY is unreachable or unavailable, although replicaset change operations will not be possible, except for forcePrimaryInstance().
Undefined killSandboxInstance | ( | Integer | port, |
Dictionary | options | ||
) |
Kills a running MySQL Server instance on localhost.
port | The port of the instance to be killed. |
options | Optional dictionary with options affecting the result. |
This function will kill the process of a running MySQL Server instance on the local host. The following options affect the result:
The sandboxDir must be the one where the MySQL instance was deployed. If not specified it will use:
~/mysql-sandboxes on Unix-like systems or %userprofile%\MySQL\mysql-sandboxes on Windows systems.
If the instance is not located on the used path an error will occur.
Cluster rebootClusterFromCompleteOutage | ( | String | clusterName, |
Dictionary | options | ||
) |
Brings a cluster back ONLINE when all members are OFFLINE.
clusterName | Optional The name of the cluster to be rebooted. |
options | Optional dictionary with options that modify the behavior of this function. |
The options dictionary can contain the next values:
The value for switchCommunicationStack is used to choose which Group Replication communication stack must be used in the Cluster after the reboot is complete. It's used to set the value of the Group Replication system variable 'group_replication_communication_stack'.
When set to legacy 'XCom', all internal GCS network traffic (PAXOS and communication infrastructure) flows through a separate network address: the localAddress.
When set to 'MySQL', such traffic re-uses the existing MySQL Server facilities to establish connections among Cluster members. It allows a simpler and safer setup as it obsoletes the usage of IP allowlists (ipAllowlist), removes the explicit need to have a separate network address (localAddress), and introduces user-based authentication.
The option is used to switch the communication stack previously in use by the Cluster, to another one. Setting the same communication stack results in no changes.
The ipAllowlist format is a comma separated list of IP addresses or subnet CIDR notation, for example: 192.168.1.0/24,10.0.0.1. By default the value is set to AUTOMATIC, allowing addresses from the instance private network to be automatically set for the allowlist.
The value for localAddress is used to set the Group Replication system variable 'group_replication_local_address'. The localAddress option accepts values in the format: 'host:port' or 'host:' or ':port'. If the specified value does not include a colon (:) and it is numeric, then it is assumed to be the port, otherwise it is considered to be the host. When the host is not specified, the default value is the value of the system variable 'report_host' if defined (i.e., not 'NULL'), otherwise it is the hostname value. When the port is not specified, the default value is the port of the target instance if the communication stack in use by the Cluster is 'MYSQL', otherwise, port * 10 + 1 when the communication stack is 'XCOM'. In case the automatically determined default port value is invalid (> 65535) then an error is thrown.
The value for paxosSingleLeader is used to enable or disable the Group Communication engine to operate with a single consensus leader when the Cluster is in single-primary more. When enabled, the Cluster uses a single leader to drive consensus which improves performance and resilience in single-primary mode, particularly when some of the Cluster's members are unreachable.
The option is available on MySQL 8.0.31 or newer and the default value is 'OFF'.
The option is used to switch the value of paxosSingleLeader previously in use by the Cluster, to either enable or disable it.
This function reboots a cluster from complete outage. It obtains the Cluster information from the instance MySQL Shell is connected to and uses the most up-to-date instance in regards to transactions as new seed instance to recover the cluster. The remaining Cluster members are automatically rejoined.
On success, the restored cluster object is returned by the function.
The current session must be connected to a former instance of the cluster.
If name is not specified, the default cluster will be returned.
Undefined startSandboxInstance | ( | Integer | port, |
Dictionary | options | ||
) |
Starts an existing MySQL Server instance on localhost.
port | The port where the instance listens for MySQL connections. |
options | Optional dictionary with options affecting the result. |
This function will start an existing MySQL Server instance on the local host. The following options affect the result:
The sandboxDir must be the one where the MySQL instance was deployed. If not specified it will use:
~/mysql-sandboxes on Unix-like systems or %userprofile%\MySQL\mysql-sandboxes on Windows systems.
If the instance is not located on the used path an error will occur.
Undefined stopSandboxInstance | ( | Integer | port, |
Dictionary | options | ||
) |
Stops a running MySQL Server instance on localhost.
port | The port of the instance to be stopped. |
options | Optional dictionary with options affecting the result. |
This function will gracefully stop a running MySQL Server instance on the local host. The following options affect the result:
The sandboxDir must be the one where the MySQL instance was deployed. If not specified it will use:
~/mysql-sandboxes on Unix-like systems or %userprofile%\MySQL\mysql-sandboxes on Windows systems.
If the instance is not located on the used path an error will occur.
Undefined upgradeMetadata | ( | Dictionary | options | ) |
Upgrades (or restores) the metadata to the version supported by the Shell.
options | Optional dictionary with option for the operation. |
This function will compare the version of the installed metadata schema with the version of the metadata schema supported by this Shell. If the installed metadata version is lower, an upgrade process will be started.
The options dictionary accepts the following attributes:
The Upgrade Process
When upgrading the metadata schema of clusters deployed by Shell versions before 8.0.19, a rolling upgrade of existing MySQL Router instances is required. This process allows minimizing disruption to applications during the upgrade.
The rolling upgrade process must be performed in the following order:
Failed Upgrades
If the installed metadata is not available because a previous call to this function ended unexpectedly, this function will restore the metadata to the state it was before the failed upgrade operation.
int verbose |
Controls debug message verbosity for sandbox related dba operations.
The assigned value can be either boolean or integer, the result depends on the assigned value:
Session session |
The session the dba object will use by default.
Reference to the MySQL session that will be used as the default target for AdminAPI operations such as getCluster() or createCluster().
This is a read-only property.