首页 > 数据库 >MySQL命令rebootClusterFromCompleteOutage重启集群注意事项

MySQL命令rebootClusterFromCompleteOutage重启集群注意事项

时间:2024-10-12 14:35:34浏览次数:1  
标签:7306 Cluster rebootClusterFromCompleteOutage MySQL mysqlu03 instance mysqlu01 注意

rebootClusterFromCompleteOutage()是MySQL Shell中的一个实用命令,用于在 InnoDB 集群遇到完全中断 (例如,当组复制在所有成员实例上停止时)后重新配置和恢复集群。这个命令允许你连接到集群中的一个 MySQL 实例,并使用该实例的元数据来恢复整个集群。

在MySQL Shell中使用rebootClusterFromCompleteOutage命令启动集群(MySQL InnoDB Cluster)

MySQL  mysqlu01:7306 ssl  JS > dba.rebootClusterFromCompleteOutage()
Restoring the Cluster 'Cluster_GSP' from complete outage...

Cluster instances: 'mysqlu01:7306' (OFFLINE), 'mysqlu02:7306' (OFFLINE), 'mysqlu03:7306' (OFFLINE)
Waiting for instances to apply pending received transactions...
Validating instance configuration at mysqlu01:7306...

This instance reports its own address as mysqlu01:7306

Instance configuration is suitable.
* Waiting for seed instance to become ONLINE...
mysqlu01:7306 was restored.
Validating instance configuration at mysqlu02:7306...

This instance reports its own address as mysqlu02:7306

Instance configuration is suitable.
Rejoining instance 'mysqlu02:7306' to cluster 'Cluster_GSP'...

Re-creating recovery account...
NOTE: User 'mysql_innodb_cluster_201'@'%' already existed at instance 'mysqlu01:7306'. It will be deleted and created again with a new password.

* Waiting for the Cluster to synchronize with the PRIMARY Cluster...
** Transactions replicated  ############################################################  100% 

The instance 'mysqlu02:7306' was successfully rejoined to the cluster.

Validating instance configuration at mysqlu03:7306...

This instance reports its own address as mysqlu03:7306

Instance configuration is suitable.
Rejoining instance 'mysqlu03:7306' to cluster 'Cluster_GSP'...

Re-creating recovery account...
NOTE: User 'mysql_innodb_cluster_202'@'%' already existed at instance 'mysqlu01:7306'. It will be deleted and created again with a new password.

* Waiting for the Cluster to synchronize with the PRIMARY Cluster...
** Transactions replicated  ############################################################  100% 

The instance 'mysqlu03:7306' was successfully rejoined to the cluster.

The Cluster was successfully rebooted.

<Cluster:Cluster_GSP>
 MySQL  mysqlu01:7306 ssl  JS > 

那么,关于命令rebootClusterFromCompleteOutage的一些知识点或注意事项,必须弄清楚,避免踩坑或稀里糊涂的。下面是一些简单总结,当前测试环境为MySQL 8.0.35,随着版本的变更,可能会有一些特性变化,请以实际情况为准。

1.确保集群的所有成员/节点在运行命令之前都已启动:在执行dba.rebootClusterFromCompleteOutage()命令之前,需要确保所有集群成员的MySQL实例都已启动并且可以访问。 如果无法访问任何集群成员,该命令将失败。如下所示:

情况1: 三个节点的MySQL服务都未启动的情况

 MySQL  JS > \c icadmin@mysqlu03:7306
Creating a session to 'icadmin@mysqlu03:7306'
MySQL Error 2003 (HY000): Can't connect to MySQL server on 'mysqlu03:7306' (111)
 MySQL  JS >

三个节点都没有启动时,MySQL Shell甚至都无法连接上。

情况2: 三个节点中,有一个或两个节点未启动情况

 MySQL  mysqlu01:7306 ssl  JS > dba.rebootClusterFromCompleteOutage()
Restoring the Cluster 'Cluster_GSP' from complete outage...

Cluster instances: 'mysqlu01:7306' (OFFLINE), 'mysqlu02:7306' (UNREACHABLE), 'mysqlu03:7306' (UNREACHABLE)
WARNING: One or more instances of the Cluster could not be reached and cannot be rejoined nor ensured to be OFFLINE: 'mysqlu02:7306', 'mysqlu03:7306'. Cluster may diverge and become inconsistent unless all instances are either reachable or certain to be OFFLINE and not accepting new transactions. You may use the 'force' option to bypass this check and proceed anyway.
ERROR: Could not determine if Cluster is completely OFFLINE
Dba.rebootClusterFromCompleteOutage: Could not determine if Cluster is completely OFFLINE (RuntimeError)
 MySQL  mysqlu01:7306 ssl  JS > 

2.这种启动方式,它会自动找出GTID值最大的成员/节点作为MGR的引导节点吗?如果不能,是否需要mysql shell连接到集群中GTID最大的成员/节点,然后执行这个命令呢?

如下所示,集群中有三个节点mysqlu01,mysqlu02,mysqlu03

mysql> select * from performance_schema.replication_group_members order by member_host\G;
*************************** 1. row ***************************
              CHANNEL_NAME: group_replication_applier
                 MEMBER_ID: 591280ce-bb5f-11ee-8862-00505697b437
               MEMBER_HOST: mysqlu01
               MEMBER_PORT: 7306
              MEMBER_STATE: ONLINE
               MEMBER_ROLE: PRIMARY
            MEMBER_VERSION: 8.0.35
MEMBER_COMMUNICATION_STACK: MySQL
*************************** 2. row ***************************
              CHANNEL_NAME: group_replication_applier
                 MEMBER_ID: 6ae7d68b-ba96-11ee-8092-005056971158
               MEMBER_HOST: mysqlu02
               MEMBER_PORT: 7306
              MEMBER_STATE: ONLINE
               MEMBER_ROLE: SECONDARY
            MEMBER_VERSION: 8.0.35
MEMBER_COMMUNICATION_STACK: MySQL
*************************** 3. row ***************************
              CHANNEL_NAME: group_replication_applier
                 MEMBER_ID: 4fc54bd5-bbf3-11ee-b588-0050569783ac
               MEMBER_HOST: mysqlu03
               MEMBER_PORT: 7306
              MEMBER_STATE: ONLINE
               MEMBER_ROLE: SECONDARY
            MEMBER_VERSION: 8.0.35
MEMBER_COMMUNICATION_STACK: MySQL
3 rows in set (0.00 sec)

ERROR: 
No query specified

mysql>

我们先用命令将节点mysqlu03的MySQL实例关闭

sudo systemctl stop mysqld.service

然后在mysqlu01中进行一些插入操作,人为模拟节点mysqlu01的GTID要大于mysqlu03

insert into test
select 1007, 'k1007' union all
select 1008, 'k1008';


mysql> insert into test
    -> select 1007, 'k1007' union all
    -> select 1008, 'k1008';
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

然后先后依次将mysqlu02,mysqlu01的MySQL服务关闭,然后启动这三个节点的MySQL服务,然后使用mysqlsh连接到mysqlu03上来启动

mysqlsh icadmin@mysqlu03:7306 

mysqlsh icadmin@mysqlu03:7306 --log-level=DEBUG3

如下所示:

 MySQL  mysqlu03:7306 ssl  JS > dba.rebootClusterFromCompleteOutage()
Restoring the Cluster 'Cluster_GSP' from complete outage...

Cluster instances: 'mysqlu01:7306' (OFFLINE), 'mysqlu02:7306' (OFFLINE), 'mysqlu03:7306' (OFFLINE)
Waiting for instances to apply pending received transactions...
Switching over to instance 'mysqlu01:7306' (which has the highest GTID set), to be used as seed.
NOTE: The instance 'mysqlu01:7306' is running auto-rejoin process, which will be cancelled.

Validating instance configuration at mysqlu01:7306...

This instance reports its own address as mysqlu01:7306

Instance configuration is suitable.
NOTE: Cancelling active GR auto-initialization at mysqlu01:7306
* Waiting for seed instance to become ONLINE...
mysqlu01:7306 was restored.
Validating instance configuration at mysqlu02:7306...

This instance reports its own address as mysqlu02:7306

Instance configuration is suitable.
Rejoining instance 'mysqlu02:7306' to cluster 'Cluster_GSP'...

Re-creating recovery account...
NOTE: User 'mysql_innodb_cluster_201'@'%' already existed at instance 'mysqlu01:7306'. It will be deleted and created again with a new password.

* Waiting for the Cluster to synchronize with the PRIMARY Cluster...
** Transactions replicated  ############################################################  100% 

The instance 'mysqlu02:7306' was successfully rejoined to the cluster.

Validating instance configuration at mysqlu03:7306...

This instance reports its own address as mysqlu03:7306

Instance configuration is suitable.
Rejoining instance 'mysqlu03:7306' to cluster 'Cluster_GSP'...

Re-creating recovery account...
NOTE: User 'mysql_innodb_cluster_202'@'%' already existed at instance 'mysqlu01:7306'. It will be deleted and created again with a new password.

* Waiting for the Cluster to synchronize with the PRIMARY Cluster...
** Transactions replicated  ############################################################  100% 

The instance 'mysqlu03:7306' was successfully rejoined to the cluster.

The Cluster was successfully rebooted.

<Cluster:Cluster_GSP>
 MySQL  mysqlu03:7306 ssl  JS >

如上所示,从"Switching over to instance 'mysqlu01:7306' (which has the highest GTID set), to be used as seed."这个输出信息,我们可以清楚的 看到MySQL Shell中使用命令启动集群的时候,它会自动判断哪一个节点的GTID值最大,这个测试案例中,mysqlu01节点的GTID值最大,它就将mysqlu01作为 MGR的引导节点。所以,使用命令(dba.rebootClusterFromCompleteOutage())重启集群时,可以连接到集群的任一节点去启动集群。

注意:早期的版本,如果重新启动集群,需要连接到GTID最新的实例,也就是说必须连接到具有GTID超集的成员,即在中断之前应用了最多事务的实例。如果当前连接的实例的GTID不是最新(最大的值)的,则会报错,如下所示

Dba.rebootClusterFromCompleteOutage: The active session instance isn't the most updated 
in comparison with the ONLINE instances of the Cluster's metadata. 
Please use the most up to date instance: '***.***.***.***:3306'. (RuntimeError)

这个仅仅在早期版本中有这个问题。

另外,需要注意的是,如果集群中三个节点的GTID一致,如果集群关闭前主节点为mysqlu01,如果此时MySQL shell连接到mysqlu03去启动集群,此时mysqlu03会切换为主节点(PRIMARY),而mysqlu01会切换为从节点(SECOND)

3.使用force选项会忽略GTID集的分歧,并将所选成员作为主节点,丢弃未包含在所选成员GTID集中的任何事务。如果此过程失败,并且集群元数据已严重损坏, 你可能需要删除元数据并从头开始重新创建集群。这是一个危险的操作,因为它将删除所有集群元数据,并且不能撤销。 在实际操作中,应尽量避免使用force选项,因为它可能会引起数据不一致。只有在你完全了解可能产生的后果,并且没有其他选择时,才应考虑使用此选项。

如果你知道哪个节点具有最大的GTID值,但无法访问其他节点,可以使用force选项来强制重启集群。这将使用剩余可联系的成员来重启集群,即使某些成员当前无法访问

4.这种方式是集群中所有节点都关闭后使用,如果只是一个节点服务器重启或MySQL服务关闭后重启,并不能使用这种方式。

标签:7306,Cluster,rebootClusterFromCompleteOutage,MySQL,mysqlu03,instance,mysqlu01,注意
From: https://www.cnblogs.com/kerrycode/p/18460479

相关文章

  • MySQL 读写分离
    优质博文:IT-BLOG-CN一、背景随着机票业务不断增长,订单库的读性能遇到了挑战,因此对订单库进行读写分离操作。主要目的是提高数据库的并发性能和可扩展性。当系统的所有写操作效率尚可,读数据请求效率较低时,比如之前订单表存放了几千万条数据,且查询订单信息需要关联十几个字......
  • MySql.Data.dll官网下载
    原文链接:https://blog.csdn.net/weixin_30668887/article/details/96468519Mysql.Data.dll官网下载在项目开发中链接MySQL数据库经常要用到Mysql.Data.dll,网上虽然有很多,但是还是比较信赖官网的今天就从官网下载一次记录一下过程1.下载地址官网地址:https://www.mysql.com/2.......
  • ORCLE与MySQL的相互转化
    1.情景展示在实际开发中,不同的地方可能所需使用的数据库是不同的。这就要求,我们开发的程序需要兼容不同的数据库,放到程序里面就是:需要有不同类型的sqlMap文件。以既要兼容MySQL,也要兼容Oracle进行举例说明。2.准备工作第一步根据已经写好的一套sql进行复制,然后,在原有sql的......
  • cmakelist 源码生成so 文件 orthanc mysql
    cmakelist.txt#Orthanc-ALightweight,RESTfulDICOMStore#Copyright(C)2012-2016SebastienJodogne,MedicalPhysics#Department,UniversityHospitalofLiege,Belgium#Copyright(C)2017-2023OsimisS.A.,Belgium#Copyright(C)2024-2024Orthanc......
  • Starrocks表的数据库字段类型及与MySQL 的差异
    最近有用到Starrocks,实际使用中基本可以当作mysql来使用,但是数据库字段还是有所不同的。与MySQL相同或相似的基础类型数值类型TINYINT、SMALLINT、INT/INTEGER、BIGINT:在Starrocks和MySQL中的定义和用途基本相似。都是用于存储整数,范围也和MySQL中的对应类型相同,例如TI......
  • 泛微e-cology安装报错 MySQL初始化问题Table 'ecology.e9_para_xxx' doestn't exist
    在安装泛微e-cology9进行初始化数据库时出现如下报错Table 'ecology.e9_para_xxx'doestn'texist 明明是在初始化数据库  数据表不存在不是很正常==经过研究  发现泛微在初始化数据库时 会执行存储过程脚本  使用dbeaver可以看到 根据代码逻辑看  如......
  • 直流负载箱的安全事项和注意事项有哪些?
    直流负载箱是用于模拟实际负载的设备,广泛应用于电力系统、电气设备测试和维护等领域。为了确保使用过程中的安全,操作人员需要了解并遵循以下安全事项和注意事项:根据实际需求选择合适的负载箱,确保其额定电压、额定电流等参数与被测设备相匹配,避免过载或欠载现象。将负载箱安装在......
  • MySQL数据备份
    MySQL数据备份是数据库管理员非常重要的工作之一。系统意外崩溃或者硬件的损坏都可能导致数据的丢失,因此MySQL管理员应该定期地备份数据,使得在意外情况发生时最大限度地减少损失。本节将介绍数据备份的3种方法。11.1.1 使用mysqldump命令备份数据mysqldump是MySQL提供的一个非......
  • mysql数据库服务器错误怎么回事
    MySQL数据库服务器错误可能由多种原因导致,这里列举一些常见的问题及其解决方法:服务未启动检查MySQL服务是否已经启动。在命令行中使用 netstartmysql (Windows)或 sudoservicemysqlstart (Linux)来尝试启动MySQL服务。配置文件错误确认my.cnf(Linux)或my.ini(Window......
  • 在Java程序中监听mysql的binlog
    目录1、背景2、mysql-binlog-connector-java简介3、准备工作1、验证数据库是否开启binlog2、开启数据库的binlog3、创建具有REPLICATIONSLAVE权限的用户4、事件类型eventType解释1、TABLE_MAP的注意事项2、获取操作的列名5、监听binlog的position1、从最新的binlog位置开始监......