MySQL Shell 9.0  /  MySQL InnoDB ReplicaSet  /  升級 InnoDB ReplicaSet

9.11 升級 InnoDB ReplicaSet

若要升級 InnoDB ReplicaSet 中的執行個體,請完成下列步驟

檢查已安裝二進位檔案的版本

  • mysqlrouter --version:檢查已安裝的 MySQL Router 版本。

  • mysqlsh --version:檢查已安裝的 MySQL Shell 版本。

  • mysqld --version:檢查已安裝的 MySQL 伺服器版本。

升級 MySQL Router。

若要升級 MySQL Router,請完成下列步驟

  1. 停止 MySQL Router。

    在 Unix 系統上,如果您使用選用的 --directory 啟動選項,則會在您啟動路由器時選取的位置建立一個包含所有產生目錄和檔案的獨立安裝。這些檔案包含 stop.sh。導覽至此目錄並發出此命令

    ./stop.sh

    在 Microsoft Windows 上,如果您使用選用的 --directory 啟動選項,則會在您啟動路由器時選取的位置建立一個包含所有產生目錄和檔案的獨立安裝。這些檔案包含 stop.ps1。導覽至此目錄並發出此命令

    .\stop.ps1

    或者,在使用 systemd 的 Linux 系統上,請發出下列指令來停止 MySQL Router 服務

    systemctl stop mysqlrouter.service

    否則,請終止相關 mysqlrouter 程序的程序 ID (PID)

  2. 取得並安裝最新版本的 MySQL Router。

  3. 啟動 MySQL Router。

    在 Unix 系統上,如果您使用選用的 --directory 啟動選項,則會在您選取的位置建立一個包含所有產生目錄和檔案的獨立安裝。這些檔案包含 start.sh。導覽至此目錄並發出此命令

    ./start.sh

    如果新路由器的路徑已變更,您必須更新 start.sh shell 腳本以反映路徑。

    #!/bin/bash
    basedir=/tmp/myrouter
    ROUTER_PID=$basedir/mysqlrouter.pid /usr/bin/mysqlrouter -c $basedir/mysqlrouter.conf &
    disown %-

    如果您手動升級 MySQL Router,而不是使用套件管理,您可以更新 basedir=。再次啟動路由器也會重新產生 start.sh shell 腳本。

    或者,在使用 systemd 的 Linux 系統上,請發出下列指令來啟動 MySQL Router 服務

    systemctl start mysqlrouter.service

    在 Microsoft Windows 上,如果您使用選用的 --directory 啟動選項,則會在您選取的位置建立一個包含所有產生目錄和檔案的獨立安裝。這些檔案包含 start.ps1。導覽至此目錄並發出此命令

    .\start.ps1

    在使用新的路由器二進位檔案啟動 MySQL Router 時,路由器的版本會升級

    mysqlrouter --version

升級 MySQL Shell

透過安裝新的二進位檔案,並停止和啟動 MySQL Shell 來升級 MySQL Shell

  1. 取得並安裝最新版本的 MySQL Shell。

  2. 發出下列指令來停止並結束 MySQL Shell

    \q
  3. 透過發出下列指令,從命令列重新啟動 MySQL Shell

    mysqlsh
  4. 升級 InnoDB ReplicaSet 中繼資料

    • 若要升級 InnoDB ReplicaSet,請將 MySQL Shell 的全域工作階段連線至您的 ReplicaSet,並使用 dba.upgradeMetadata() 作業將 ReplicaSet 的中繼資料升級為新的中繼資料。

      dba.upgradeMetadata() 函數會將已安裝中繼資料結構描述的版本與此 Shell 支援的中繼資料結構描述版本進行比較。如果已安裝的中繼資料版本較低,則會啟動升級程序。

    中繼資料升級

    如果 ReplicaSet 已使用最新版本,中繼資料升級可能會沒有作用。

升級 MySQL 伺服器

先升級所有次要執行個體,然後再升級主要執行個體,以升級 MySQL 伺服器。

升級 MySQL 伺服器是選用的

升級 MySQL 伺服器是選用的。伺服器升級的影響可能大於升級 MySQL Shell 和 MySQL Router。此外,您應該始終將 MySQL Shell 和 MySQL Router 維持在最新版本,即使伺服器不是最新版本也是如此;這適用於 InnoDB Cluster 和 ReplicaSet。

  1. 發出下列其中一個命令來停止 MySQL 伺服器

    • 如果 MySQL 伺服器使用 systemd,請發出

      systemctl stop mysqld
    • 如果 MySQL 伺服器使用 init.d,請發出

      /etc/init.d/mysql stop
    • 如果 MySQL 伺服器使用 service,請發出

      service mysql stop
    • 如果您在 Microsoft Windows 上部署 MySQL 伺服器,請發出

      mysqladmin -u root -p shutdown
  2. 取得並安裝最新版本的 MySQL 伺服器。

  3. 發出下列其中一個命令來啟動 MySQL 伺服器

    • 如果 MySQL 伺服器使用 systemd,請發出

      systemctl start mysqld
    • 如果 MySQL 伺服器使用 init.d,請發出

      /etc/init.d/mysql start
    • 如果 MySQL 伺服器使用 service,請發出

      service mysql start
    • 如果您在 Microsoft Windows 上部署 MySQL 伺服器,請發出

      mysqld
  4. 升級所有次要執行個體後,請升級主要執行個體以完成升級程序。

    InnoDB ReplicaSet 中沒有自動主要切換。您需要在升級主要執行個體之前,將主要執行個體設定為您已升級的成員。

    將已升級的次要執行個體設定為主要執行個體

    <ReplicaSet>.setPrimaryInstance('<host>:<port>')

    使用 <ReplicaSet>.setPrimaryInstance() 作業,安全地將 ReplicaSet 的主要執行個體變更為另一個執行個體。目前的主要執行個體會降級為次要執行個體並設為唯讀,而升級的執行個體會成為新的主要執行個體,並設為讀寫。所有其他次要執行個體都會更新以從新的主要執行個體進行複寫。您已針對 ReplicaSet 啟動的 MySQL Router 執行個體會自動開始將讀寫用戶端重新導向至新的主要執行個體。

    升級的主要執行個體。升級後,您可以使用 <ReplicaSet>.setPrimaryInstance() 將此升級的執行個體還原回主要執行個體。如需更多資訊,請參閱第 9.7 節「變更主要執行個體」

升級後狀態檢查

在升級 MySQL Router、MySQL Shell 和 MySQL 伺服器後

  • 發出 <ReplicaSet>.status() 來檢查 ReplicaSet 的狀態。在下列範例中,<ReplicaSet>.status() 會傳回 instanceErrors

      mysqlsh> <ReplicaSet>.status();
    {
        "replicaSet": {
            "name": "myReplicaSet",
            "primary": "example-el7-1644251369:30014",
            "status": "AVAILABLE",
            "statusText": "All instances available.",
            "topology": {
                "example-el7-1644251369:30011": {
                    "address": "example-el7-1644251369:30011",
                    "instanceErrors": [
                        "NOTE: The required parallel-appliers settings are not enabled on the instance. 
                               Use dba.configureReplicaSetInstance() to fix it."
                    ],
                    "instanceRole": "SECONDARY",
                    "mode": "R/O",
                    "replication": {
                        "applierStatus": "APPLIED_ALL",
                        "applierThreadState": "Waiting for an event from Coordinator",
                        "applierWorkerThreads": 4,
                        "receiverStatus": "ON",
                        "receiverThreadState": "Waiting for source to send event",
                        "replicationLag": null
                    },
                    "status": "ONLINE"
                },
                "example-el7-1644251369:30014": {
                    "address": "example-el7-1644251369:30014",
                    "instanceErrors": [
                        "NOTE: The required parallel-appliers settings are not enabled on the instance. 
                               Use dba.configureReplicaSetInstance() to fix it."
                    ],
                    "instanceRole": "PRIMARY",
                    "mode": "R/W",
                    "status": "ONLINE"
                },
                "example-el7-1644251369:30017": {
                    "address": "example-el7-1644251369:30017",
                    "instanceErrors": [
                        "NOTE: The required parallel-appliers settings are not enabled on the instance. 
                               Use dba.configureReplicaSetInstance() to fix it."
                    ],
                    "instanceRole": "SECONDARY",
                    "mode": "R/O",
                    "replication": {
                        "applierStatus": "APPLIED_ALL",
                        "applierThreadState": "Waiting for an event from Coordinator",
                        "applierWorkerThreads": 4,
                        "receiverStatus": "ON",
                        "receiverThreadState": "Waiting for source to send event",
                        "replicationLag": null
                    },
                    "status": "ONLINE"
                },
                "example-el7-1644251369:30021": {
                    "address": "example-el7-1644251369:30021",
                    "instanceErrors": [
                        "NOTE: The required parallel-appliers settings are not enabled on the instance. 
                               Use dba.configureReplicaSetInstance() to fix it."
                    ],
                    "instanceRole": "SECONDARY",
                    "mode": "R/O",
                    "replication": {
                        "applierStatus": "APPLIED_ALL",
                        "applierThreadState": "Waiting for an event from Coordinator",
                        "applierWorkerThreads": 4,
                        "receiverStatus": "ON",
                        "receiverThreadState": "Waiting for source to send event",
                        "replicationLag": null
                    },
                    "status": "ONLINE"
                }
            },
            "type": "ASYNC"
        }
    }

    instanceError 告訴我們發出 dba.configureReplicaSetInstance() 來修正錯誤。

    dba.configureReplicaSetInstance(instance) 會設定您想要在 ReplicaSet 中使用的每個執行個體。MySQL Shell 可以連線至執行個體,然後設定它,或者您可以傳入 instance 名稱以設定特定的遠端執行個體。如需更多資訊,請參閱第 6.2.3 節「持續設定」

    如果 PRIMARY 成員將 read_onlysuper_read_only 設定為 ON,則下列範例顯示 <ReplicaSet>.status() 的輸出

    mysqlsh > <ReplicaSet>.status();
    replicaset.status();
    {
        "replicaSet": {
            "name": "myReplicaSet",
            "primary": "example-el7-1644251369:30014",
            "status": "UNAVAILABLE",
            "statusText": "PRIMARY instance is not available, but there is at least one SECONDARY 
                           that could be force-promoted.",
            "topology": {
                "example-el7-1644251369:30011": {
                    "address": "example-el7-1644251369:30011",
                    "instanceErrors": [
                        "NOTE: The required parallel-appliers settings are not enabled on the instance. 
                               Use dba.configureReplicaSetInstance() to fix it."
                    ],
                    "instanceRole": "SECONDARY",
                    "mode": "R/O",
                    "replication": {
                        "applierStatus": "APPLIED_ALL",
                        "applierThreadState": "Waiting for an event from Coordinator",
                        "applierWorkerThreads": 4,
                        "receiverStatus": "ON",
                        "receiverThreadState": "Waiting for source to send event",
                        "replicationLag": null
                    },
                    "status": "ONLINE"
                },
                "example-el7-1644251369:30014": {
                    "address": "example-el7-1644251369:30014",
                    "fenced": true,
                    "instanceErrors": [
                        "ERROR: Instance is a PRIMARY but is READ-ONLY: read_only=ON, super_read_only=ON",
                        "NOTE: The required parallel-appliers settings are not enabled on the instance. 
                               Use dba.configureReplicaSetInstance() to fix it."
                    ],
                    "instanceRole": "PRIMARY",
                    "mode": "R/O",
                    "status": "ERROR"
                },
                "example-el7-1644251369:30017": {
                    "address": "example-el7-1644251369:30017",
                    "instanceErrors": [
                        "NOTE: The required parallel-appliers settings are not enabled on the instance. 
                               Use dba.configureReplicaSetInstance() to fix it."
                    ],
                    "instanceRole": "SECONDARY",
                    "mode": "R/O",
                    "replication": {
                        "applierStatus": "APPLIED_ALL",
                        "applierThreadState": "Waiting for an event from Coordinator",
                        "applierWorkerThreads": 4,
                        "receiverStatus": "ON",
                        "receiverThreadState": "Waiting for source to send event",
                        "replicationLag": null
                    },
                    "status": "ONLINE"
                },
                "example-el7-1644251369:30021": {
                    "address": "example-el7-1644251369:30021",
                    "instanceErrors": [
                        "NOTE: The required parallel-appliers settings are not enabled on the instance. 
                               Use dba.configureReplicaSetInstance() to fix it."
                    ],
                    "instanceRole": "SECONDARY",
                    "mode": "R/O",
                    "replication": {
                        "applierStatus": "APPLIED_ALL",
                        "applierThreadState": "Waiting for an event from Coordinator",
                        "applierWorkerThreads": 4,
                        "receiverStatus": "ON",
                        "receiverThreadState": "Waiting for source to send event",
                        "replicationLag": null
                    },
                    "status": "ONLINE"
                }
            },
            "type": "ASYNC"
        }
    }

    如需更多資訊,請參閱第 9.10 節「檢查 InnoDB ReplicaSet 的狀態」