當 MySQL Router 連線至 Cluster、ClusterSet 或 ReplicaSet 時,需要具有正確權限的使用者帳戶。可以使用 --account
選項指定此內部使用者。在先前的版本中,MySQL Router 在每次引導啟動叢集時建立內部帳戶,這可能會導致隨著時間的推移累積許多帳戶。您可以使用 AdminAPI 設定 MySQL Router 所需的使用者帳戶。
使用 setupRouterAccount(user, [options])
操作建立 MySQL 使用者帳戶,或升級現有帳戶,以便 MySQL Router 可以使用該帳戶對 InnoDB Cluster 或 InnoDB ReplicaSet 執行操作。這是建議使用 InnoDB Cluster 和 InnoDB ReplicaSet 設定 MySQL Router 的方法。
若要將名為 myRouter1
的新 MySQL Router 帳戶新增至變數 testCluster
參照的 InnoDB Cluster,請發出
mysqlsh> testCluster.setupRouterAccount('myRouter1')
在此案例中,未指定網域,因此會使用萬用字元 (%
) 建立帳戶,這可確保建立的使用者可以從任何網域連線。若要限制帳戶只能從 JavaScript 中的 example.com
網域連線,請發出
mysql-js> testCluster.setupRouterAccount('myRouter1@example.com')
或使用 Python
mysql-py> testCluster.setup_router_account('myRouter1@example.com')
此操作會提示輸入密碼,然後使用正確的權限設定 MySQL Router 使用者。如果 InnoDB Cluster 或 InnoDB ReplicaSet 有多個執行個體,則會將建立的 MySQL Router 使用者傳播到所有執行個體。
您可以使用字典選項 {password: "
在建立使用者的相同命令中建立密碼password
"}
當您已設定 MySQL Router 使用者時,可以使用 setupRouterAccount()
操作重新設定現有使用者。在此案例中,傳入設定為 true 的 update
選項。例如,若要重新設定 myOldRouter
使用者,請在 JavaScript 中發出以下命令
mysql-js> testCluster.setupRouterAccount('myOldRouter', {'update':1})
或使用 Python
mysql-py> testCluster.setup_router_account('myOldRouter', {'update':1})
您也可以使用字典選項 {password: "
更新 MySQL Router 使用者的密碼。以下 JavaScript 範例會將 MySQL Router 使用者 newPassword
", update: 1} myRouter1
的密碼更新為 newPassword1#
mysql-js> testCluster.setupRouterAccount('myRouter1', {password: "newPassword1#",'update':1})
或使用 Python
mysql-py> testCluster.setup_router_account('myRouter1', {password: "newPassword1#", 'update':1})
也支援 SSL 憑證。以下選項可以與 setupRouterAccount()
一起使用
requireCertIssuer
:帳戶的可選 SSL 憑證簽發者。requireCertSubject
:帳戶的可選 SSL 憑證主體。-
passwordExpiration: numberOfDays | Never | Default
:帳戶的密碼到期設定。numberOfDays
:密碼到期前的天數。Never
:密碼永遠不會到期。Default
:使用系統預設值。