Bo's Oracle Station

【博客文章2024】MySQL Innodb Cluster 8.0.36组复制的单主/多主模式切换

2024-2-27 09:31| 发布者: admin| 查看: 29| 评论: 0|原作者: Bo Tang

摘要: 本博客详细介绍了MySQL Innodb Cluster 8.0.36组复制的单主到多主模式切换以及多主到单主模式切换。注意事项通过实验详细列出。
【博客文章2024】MySQL Innodb Cluster 8.0.36组复制的单主/多主模式切换


Author: Bo Tang

1. MySQL Innodb Cluster 8.0.36可以在线进行单主/多主模式切换:

 

 

2. 单主到多主模式切换:


2.1 单主模式的实验起点:

    本复制组中,node0为读写节点,node1-node6为只读节点。我们连接到集群中的任一节点的mysqld(比如node0),进行查询组复制成员的状态:


MySQL  node0:3306 ssl  SQL > select  * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------------+-------------+--------------+-------------+----------------+----------------------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST       | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |
+---------------------------+--------------------------------------+-------------------+-------------+--------------+-------------+----------------+----------------------------+
| group_replication_applier | 0f7a81ed-c950-11ee-8276-5254003b94bf | node5.example.com |        3306 | ONLINE       | SECONDARY   | 8.0.36         | XCom                       |
| group_replication_applier | 0fa42649-c94e-11ee-8ac8-5254005d656b | node2.example.com |        3306 | ONLINE       | SECONDARY   | 8.0.36         | XCom                       |
| group_replication_applier | 161cb29f-c94f-11ee-83b3-525400657e88 | node3.example.com |        3306 | ONLINE       | SECONDARY   | 8.0.36         | XCom                       |
| group_replication_applier | 4393f274-c94d-11ee-9748-6c3c8c2bd1fc | node0.example.com |        3306 | ONLINE       | PRIMARY     | 8.0.36         | XCom                       |
| group_replication_applier | 5787c895-c94f-11ee-83bb-52540066a748 | node4.example.com |        3306 | ONLINE       | SECONDARY   | 8.0.36         | XCom                       |
| group_replication_applier | 7f41e521-c950-11ee-8606-5254004bcbf4 | node6.example.com |        3306 | ONLINE       | SECONDARY   | 8.0.36         | XCom                       |
| group_replication_applier | a94a5033-c94d-11ee-9b1a-52540008a1c1 | node1.example.com |        3306 | ONLINE       | SECONDARY   | 8.0.36         | XCom                       |
+---------------------------+--------------------------------------+-------------------+-------------+--------------+-------------+----------------+----------------------------+
7 rows in set (0.0003 sec)


2.2 切换成多主模式:
    MySQL Innodb Cluster 8.0.36组复制的单主模式到多主模式的切换非常容易,可以在线进行。切换过程的进度可以查看performance_schema.events_stages_current视图。
我们连接到集群中的任一节点的mysqld(比如node0),执行切换:
 

 [root@node0 myrouter]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1092
Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql > select  group_replication_switch_to_multi_primary_mode();
+--------------------------------------------------+
| group_replication_switch_to_multi_primary_mode() |
+--------------------------------------------------+
| Mode switched to multi-primary successfully.     |
+--------------------------------------------------+
1 row in set (0.0149 sec)


    在切换过程中,MySQL Innodb Cluster进行一些列内部自检,确保数据的安全性和一致性之后,属于该组的所有成员都将成为主成员。如果成员节点的版本不同,那么所有版本高于最低版本的节点会被迫运行于只读状态,以保证数据的安全性和一致性。
2.3 reScan集群:
    从单主模式切换成多主模式后,使用getCluster访问集群会出错:
 

 [root@node0 mysql-software]# mysqlsh
MySQL Shell 8.0.36

Copyright (c) 2016, 2023, Oracle and/or its affiliates.
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 > \connect root@node0:3306
Creating a session to 'root@node0:3306'
Please provide the password for 'root@node0:3306': *********
Save password for 'root@node0:3306'? [Y]es/[N]o/Ne[v]er (default No):
Fetching schema names for auto-completion... Press ^C to stop.
Your MySQL connection id is 23
Server version: 8.0.36 MySQL Community Server - GPL
No default schema selected; type \use to set one.

 MySQL  node0:3306 ssl  JS > var cluster=getCluster('testCluster);

 MySQL  node0:3306 ssl  JS > cluster.status();
Cluster.status: The InnoDB Cluster topology type (Single-Primary) does not match the current Group Replication configuration (Multi-Primary). Please use .rescan() or change the Group Replication configuration accordingly. (RuntimeError)


    报错信息表明:组复制的配置还未更新,需要使用reScan进行更新:
 

MySQL  node0:3306 ssl  JS > cluster.rescan();
Rescanning the cluster...

Result of the rescanning operation for the 'testCluster' cluster:
{
    "name": "testCluster",
    "newTopologyMode": "Multi-Primary",
    "newlyDiscoveredInstances": [],
    "unavailableInstances": [],
    "updatedInstances": []
}

NOTE: The Cluster is not configured to use 'group_replication_view_change_uuid', which is required for InnoDB ClusterSet. Configuring it requires a full Cluster reboot.
Would you like 'group_replication_view_change_uuid' to be configured automatically? [Y/n]: Y
NOTE: The Cluster's group_replication_view_change_uuid is not set.
Generating and setting a value for group_replication_view_change_uuid...
NOTE: The Cluster must be completely taken OFFLINE and restarted (dba.rebootClusterFromCompleteOutage()) for the settings to be effective
Updating group_replication_view_change_uuid in the Cluster's metadata...
Updating group_replication_transaction_size_limit in the Cluster's metadata...
NOTE: The topology mode of the cluster changed to 'Multi-Primary'.
Updating topology mode in the cluster metadata...
Topology mode was successfully updated to 'Multi-Primary' in the cluster metadata.


    为了使group_replication_view_change_uuid生效,还需要重启整个集群:
 

MySQL  node0:3306 ssl  SQL > show variables like 'group_replication_view_change%';
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
| Variable_name                                       | Value                                                                                                                                                                                                    |
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
| group_replication_view_change_uuid                  | AUTOMATIC                                                                                                                                                                              |
+-----------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+

 

MySQL  node0:3306 ssl  JS > dba.rebootClusterFromCompleteOutage('testCluster',{force:true});
Restoring the Cluster 'testCluster' from complete outage...

Cluster instances: 'node0.example.com:3306' (ONLINE), 'node1.example.com:3306' (ONLINE), 'node2.example.com:3306' (ONLINE), 'node3.example.com:3306' (
ONLINE), 'node4.example.com:3306' (ONLINE), 'node5.example.com:3306' (ONLINE), 'node6.example.com:3306' (ONLINE)
Waiting for instances to apply pending received transactions...
Validating instance configuration at node0:3306...

This instance reports its own address as node0.example.com:3306

Instance configuration is suitable.
* Waiting for seed instance to become ONLINE...
node0.example.com:3306 was restored.
Validating instance configuration at node1.example.com:3306...

This instance reports its own address as node1.example.com:3306

Instance configuration is suitable.
Rejoining instance 'node1.example.com:3306' to cluster 'testCluster'...

The instance 'node1.example.com:3306' was successfully rejoined to the cluster.

Validating instance configuration at node2.example.com:3306...

This instance reports its own address as node2.example.com:3306

Instance configuration is suitable.
Rejoining instance 'node2.example.com:3306' to cluster 'testCluster'...


The instance 'node2.example.com:3306' was successfully rejoined to the cluster.

Validating instance configuration at node3.example.com:3306...

This instance reports its own address as node3.example.com:3306

Instance configuration is suitable.

Rejoining instance 'node3.example.com:3306' to cluster 'testCluster'...


The instance 'node3.example.com:3306' was successfully rejoined to the cluster.


Validating instance configuration at node4.example.com:3306...

This instance reports its own address as node4.example.com:3306

Instance configuration is suitable.
Rejoining instance 'node4.example.com:3306' to cluster 'testCluster'...


The instance 'node4.example.com:3306' was successfully rejoined to the cluster.


Validating instance configuration at node5.example.com:3306...

This instance reports its own address as node5.example.com:3306

Instance configuration is suitable.
Rejoining instance 'node5.example.com:3306' to cluster 'testCluster'...

The instance 'node5.example.com:3306' was successfully rejoined to the cluster.


Validating instance configuration at node6.example.com:3306...

This instance reports its own address as node6.example.com:3306

Instance configuration is suitable.
Rejoining instance 'node6.example.com:3306' to cluster 'testCluster'...

The instance 'node6.example.com:3306' was successfully rejoined to the cluster.

The Cluster was successfully rebooted.


    切换完成,再次查看performance_schema.replication_group_members视图:
 

 MySQL  node0:3306 ssl  SQL > select  * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------------+-------------+--------------+-------------+----------------+----------------------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST       | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |
+---------------------------+--------------------------------------+-------------------+-------------+--------------+-------------+----------------+----------------------------+
| group_replication_applier | 0f7a81ed-c950-11ee-8276-5254003b94bf | node5.example.com |        3306 | ONLINE       | PRIMARY     | 8.0.36         | XCom                       |
| group_replication_applier | 0fa42649-c94e-11ee-8ac8-5254005d656b | node2.example.com |        3306 | ONLINE       | PRIMARY     | 8.0.36         | XCom                       |
| group_replication_applier | 161cb29f-c94f-11ee-83b3-525400657e88 | node3.example.com |        3306 | ONLINE       | PRIMARY     | 8.0.36         | XCom                       |
| group_replication_applier | 4393f274-c94d-11ee-9748-6c3c8c2bd1fc | node0.example.com |        3306 | ONLINE       | PRIMARY     | 8.0.36         | XCom                       |
| group_replication_applier | 5787c895-c94f-11ee-83bb-52540066a748 | node4.example.com |        3306 | ONLINE       | PRIMARY     | 8.0.36         | XCom                       |
| group_replication_applier | 7f41e521-c950-11ee-8606-5254004bcbf4 | node6.example.com |        3306 | ONLINE       | PRIMARY     | 8.0.36         | XCom                       |
| group_replication_applier | a94a5033-c94d-11ee-9b1a-52540008a1c1 | node1.example.com |        3306 | ONLINE       | PRIMARY     | 8.0.36         | XCom                       |
+---------------------------+--------------------------------------+-------------------+-------------+--------------+-------------+----------------+----------------------------+
7 rows in set (0.0003 sec)


    说明MySQL Innodb Cluster已经成功地转换成多主模式:
 

 MySQL  node0:3306 ssl  JS > cluster.status();
{
    "clusterName": "testCluster",
    "defaultReplicaSet": {
        "name": "default",
        "ssl": "REQUIRED",
        "status": "OK",
        "statusText": "Cluster is ONLINE and can tolerate up to 3 failures.",
        "topology": {
            "node0.example.com:3306": {
                "address": "node0.example.com:3306",
                "memberRole": "PRIMARY",
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            },
            "node1.example.com:3306": {
                "address": "node1.example.com:3306",
                "memberRole": "PRIMARY",
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            },
            "node2.example.com:3306": {
                "address": "node2.example.com:3306",
                "memberRole": "PRIMARY",
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            },
            "node3.example.com:3306": {
                "address": "node3.example.com:3306",
                "memberRole": "PRIMARY",
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            },
            "node4.example.com:3306": {
                "address": "node4.example.com:3306",
                "memberRole": "PRIMARY",
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            },
            "node5.example.com:3306": {
                "address": "node5.example.com:3306",
                "memberRole": "PRIMARY",
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            },
            "node6.example.com:3306": {
                "address": "node6.example.com:3306",
                "memberRole": "PRIMARY",
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            }
        },
        "topologyMode": "Multi-Primary"
    },
    "groupInformationSourceMember": "node5.example.com:3306"
}
 MySQL  node0:3306 ssl  JS >


2.4 MySQL Router的连接测试:
    因为集群中不存在只读节点,所以即使使用6447这个只读端口进行连接,连接的也都是读写节点,而且还是负载均衡的:

 

[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  3911526469 |           0 |
+--------+-------------+-------------+
[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  3698559545 |           0 |
+--------+-------------+-------------+
[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  3770380176 |           0 |
+--------+-------------+-------------+
[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |   872561124 |           0 |
+--------+-------------+-------------+
[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  1433196438 |           0 |
+--------+-------------+-------------+
[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  1729370740 |           0 |
+--------+-------------+-------------+
[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  1221594379 |           0 |
+--------+-------------+-------------+


3. 多主单主模式切换:

3.1 切换成单主模式:
    MySQL Innodb Cluster 8.0.36组复制的多主模式到
单主模式的切换非常容易,可以在线进行。切换过程的进度可以查看performance_schema.events_stages_current视图。我们连接到集群中的任一节点的mysqld(比如node0),执行切换:
 

[root@node0 myrouter]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1092
Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select  group_replication_switch_to_single_primary_mode() ;
+---------------------------------------------------+
| group_replication_switch_to_single_primary_mode() |
+---------------------------------------------------+
| Mode switched to single-primary successfully.     |
+---------------------------------------------------+
1 row in set (0.02 sec)


3.2 reScan集群:
    从多主模式切换成单主模式后,使用getCluster访问集群会出错:
 
[root@node0 myrouter]# mysqlsh
MySQL Shell 8.0.36

Copyright (c) 2016, 2023, Oracle and/or its affiliates.
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 > \connect root@node0:3306
Creating a session to 'root@node0:3306'
Please provide the password for 'root@node0:3306': *********
Save password for 'root@node0:3306'? [Y]es/[N]o/Ne[v]er (default No):
Fetching schema names for auto-completion... Press ^C to stop.
Your MySQL connection id is 1178
Server version: 8.0.36 MySQL Community Server - GPL
No default schema selected; type \use to set one.
 MySQL  node0:3306 ssl  JS > var cluster=dba.getCluster('testCluster') ;
 MySQL  node0:3306 ssl  JS > cluster.status() ;
Cluster.status: The InnoDB Cluster topology type (Multi-Primary) does not match the current Group Replication configuration (Single-Primary). Please use .rescan() or change the Group Replication configuration accordingly. (RuntimeError)

    报错信息表明:组复制的配置还未更新,需要使用reScan进行更新:
 
 MySQL  node0:3306 ssl  JS > cluster.rescan();
Rescanning the cluster...

Result of the rescanning operation for the 'testCluster' cluster:
{
    "name": "testCluster",
    "newTopologyMode": "Single-Primary",
    "newlyDiscoveredInstances": [],
    "unavailableInstances": [],
    "updatedInstances": []
}

NOTE: The Cluster is not configured to use 'group_replication_view_change_uuid', which is required for InnoDB ClusterSet. Configuring it requires a full Cluster reboot.
Would you like 'group_replication_view_change_uuid' to be configured automatically? [Y/n]: Y
WARNING: The current Cluster group_replication_view_change_uuid setting does not allow ClusterSet to be implemented, because it's set but not yet effective.
NOTE: The Cluster must be completely taken OFFLINE and restarted (dba.rebootClusterFromCompleteOutage()) for the settings to be effective
NOTE: The topology mode of the cluster changed to 'Single-Primary'.
Updating topology mode in the cluster metadata...
Topology mode was successfully updated to 'Single-Primary' in the cluster metadata.


    为了使group_replication_view_change_uuid生效,还需要重启整个集群。重启过程同本文2.3部分中的描述,此处略。
    切换完成,再次查看performance_schema.replication_group_members视图,我们的环境中node5被设定成唯一的主节点:
 

mysql> select   * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------------+-------------+--------------+-------------+----------------+----------------------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST       | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |
+---------------------------+--------------------------------------+-------------------+-------------+--------------+-------------+----------------+----------------------------+
| group_replication_applier | 0f7a81ed-c950-11ee-8276-5254003b94bf | node5.example.com |        3306 | ONLINE       | PRIMARY     | 8.0.36         | XCom                       |
| group_replication_applier | 0fa42649-c94e-11ee-8ac8-5254005d656b | node2.example.com |        3306 | ONLINE       | SECONDARY   | 8.0.36         | XCom                       |
| group_replication_applier | 161cb29f-c94f-11ee-83b3-525400657e88 | node3.example.com |        3306 | ONLINE       | SECONDARY   | 8.0.36         | XCom                       |
| group_replication_applier | 4393f274-c94d-11ee-9748-6c3c8c2bd1fc | node0.example.com |        3306 | ONLINE       | SECONDARY   | 8.0.36         | XCom                       |
| group_replication_applier | 5787c895-c94f-11ee-83bb-52540066a748 | node4.example.com |        3306 | ONLINE       | SECONDARY   | 8.0.36         | XCom                       |
| group_replication_applier | 7f41e521-c950-11ee-8606-5254004bcbf4 | node6.example.com |        3306 | ONLINE       | SECONDARY   | 8.0.36         | XCom                       |
| group_replication_applier | a94a5033-c94d-11ee-9b1a-52540008a1c1 | node1.example.com |        3306 | ONLINE       | SECONDARY   | 8.0.36         | XCom                       |
+---------------------------+--------------------------------------+-------------------+-------------+--------------+-------------+----------------+----------------------------+
7 rows in set (0.01 sec)


    说明MySQL Innodb Cluster已经成功地转换成多主模式:

 MySQL  node0:3306 ssl  JS > cluster.status() ;
{
    "clusterName": "testCluster",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "node5.example.com:3306",
        "ssl": "REQUIRED",
        "status": "OK",
        "statusText": "Cluster is ONLINE and can tolerate up to 3 failures.",
        "topology": {
            "node0.example.com:3306": {
                "address": "node0.example.com:3306",
                "memberRole": "SECONDARY",
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            },
            "node1.example.com:3306": {
                "address": "node1.example.com:3306",
                "memberRole": "SECONDARY",
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            },
            "node2.example.com:3306": {
                "address": "node2.example.com:3306",
                "memberRole": "SECONDARY",
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            },
            "node3.example.com:3306": {
                "address": "node3.example.com:3306",
                "memberRole": "SECONDARY",
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            },
            "node4.example.com:3306": {
                "address": "node4.example.com:3306",
                "memberRole": "SECONDARY",
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            },
            "node5.example.com:3306": {
                "address": "node5.example.com:3306",
                "memberRole": "PRIMARY",
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            },
            "node6.example.com:3306": {
                "address": "node6.example.com:3306",
                "memberRole": "SECONDARY",
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "applier_queue_applied",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.36"
            }
        },
        "topologyMode": "Single-Primary"
    },
    "groupInformationSourceMember": "node5.example.com:3306"
}
 MySQL  node0:3306 ssl  JS >


3.3 MySQL Router的连接测试:
    使用6447这个只读端口进行连接,连接不会连接到读写节点,而且还是负载均衡的:

 

[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  3698559545 |           1 |
+--------+-------------+-------------+
[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  3770380176 |           1 |
+--------+-------------+-------------+
[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  1433196438 |           1 |
+--------+-------------+-------------+
[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  1221594379 |           1 |
+--------+-------------+-------------+
[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  3911526469 |           1 |
+--------+-------------+-------------+
[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  3698559545 |           1 |
+--------+-------------+-------------+
[root@node0 myrouter]# mysql -h node0 -P 6447 -e "select  @@port,@@server_id,@@read_only ; " -p
Enter password:
+--------+-------------+-------------+
| @@port | @@server_id | @@read_only |
+--------+-------------+-------------+
|   3306 |  3770380176 |           1 |
+--------+-------------+-------------+




路过

雷人

握手

鲜花

鸡蛋

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-2-29 16:33 , Processed in 0.033447 second(s), 21 queries .

返回顶部