隨著 AdminAPI 的演進,某些版本可能需要您升級現有 ClusterSet、ReplicaSet 和 Cluster 的中繼資料,以確保它們與較新版本的 MySQL Shell 相容。例如,在 8.0.19 版中新增 InnoDB ReplicaSet 表示中繼資料綱要已升級至 2.0 版。無論您是否計畫使用 InnoDB ReplicaSet,若要搭配使用 MySQL Shell 8.0.19 或更新版本以及使用較舊版本的 MySQL Shell 部署的叢集,您必須升級叢集的中繼資料。
若不升級中繼資料,您就無法使用 MySQL Shell 變更使用較舊版本建立的叢集設定。例如,您只能對叢集執行讀取作業,例如
Cluster
.status()Cluster
.describe()Cluster
.options()
dba.upgradeMetadata()
操作會比較 MySQL Shell 目前連線的 ClusterSet、ReplicaSet 或 InnoDB Cluster 上找到的中繼資料綱要版本,以及此 MySQL Shell 版本支援的中繼資料綱要版本。如果找到的中繼資料版本較低,則會啟動升級程序。dba.upgradeMetadata()
函式接著會更新所有自動建立的 MySQL Router 使用者,使其具有正確的權限。名稱不是以 mysql_router_
開頭的手動建立 MySQL Router 使用者不會自動升級。這是升級 ClusterSet、ReplicaSet 或 InnoDB Cluster 的重要步驟,只有這樣才能升級 MySQL Router 中繼資料。若要檢視關於哪些向 ClusterSet、ReplicaSet 或 Cluster 註冊的 MySQL Router 執行個體需要升級中繼資料的資訊,請使用 .listRouters()
函式。例如,若要使用已指派的變數 cluster
列出與叢集相關聯的 Router 執行個體,請發出
cluster.listRouters({'onlyUpgradeRequired':'true'})
{
"clusterName": "mycluster",
"routers": {
"example.com::": {
"hostname": "example.com",
"lastCheckIn": "2019-11-26 10:10:37",
"roPort": 6447,
"roXPort": 64470,
"rwPort": 6446,
"rwXPort": 64460,
"version": "8.0.18"
}
}
}
在此範例中,listRouters()
函式中包含 onlyUpgradeRequired
選項。onlyUpgradeRequired
是一個布林值,可啟用篩選,因此傳回的 JSON 物件中只會包含支援舊版中繼資料綱要且需要升級的路由器執行個體。
若要升級 ClusterSet、ReplicaSet 或叢集的中繼資料,請將 MySQL Shell 的全域工作階段連線至您的 ClusterSet、ReplicaSet 或叢集,並使用 dba.upgradeMetadata()
操作,將 ClusterSet、ReplicaSet 或叢集的中繼資料升級至新的中繼資料。例如
mysql-js> shell.connect('user@example.com:3306')
mysql-js> dba.upgradeMetadata()
InnoDB Cluster Metadata Upgrade
The cluster you are connected to is using an outdated metadata schema version
1.0.1 and needs to be upgraded to 2.0.0.
Without doing this upgrade, no AdminAPI calls except read only operations will
be allowed.
The grants for the MySQL Router accounts that were created automatically when
bootstrapping need to be updated to match the new metadata version's
requirements.
Updating router accounts...
NOTE: 2 router accounts have been updated.
Upgrading metadata at 'example.com:3306' from version 1.0.1 to version 2.0.0.
Creating backup of the metadata schema...
Step 1 of 1: upgrading from 1.0.1 to 2.0.0...
Removing metadata backup...
Upgrade process successfully finished, metadata schema is now on version 2.0.0
如果安裝的中繼資料版本較低,則會啟動升級程序。
dba.upgradeMetadata()
函式接受下列選項
dryRun
:是一個布林值,用於啟用升級程序的試執行。如果使用dryRun
,則dba.upgradeMetadata()
函式會判斷是否需要中繼資料升級或還原,並在不實際執行操作的情況下通知您。
如果您遇到與 ClusterSet、ReplicaSet 或叢集管理使用者遺失權限相關的錯誤,請使用相關的 .setupAdminAccount()
操作,並搭配 update 選項,以授予使用者正確的權限
-
建立或升級具有管理 InnoDB 叢集所需權限的 MySQL 使用者帳戶:
<Cluster>.setupAdminAccount(user, options)
請參閱InnoDB 叢集管理員帳戶。
建立或升級具有管理 InnoDB ReplicaSet 所需權限的 MySQL 使用者帳戶:
<ReplicaSet>.setupAdminAccount(user, options)