Skip to content

Latest commit

 

History

History
executable file
·
65 lines (52 loc) · 1.41 KB

主从切换过程.md

File metadata and controls

executable file
·
65 lines (52 loc) · 1.41 KB

主从切换过程

注:主从切换过程中,尽量主从之间不要有大事务在执行,否则会卡住等待所有事务处理完毕 切换主从成功后,需检查各应用是否仍能够正常运行

在18主机上执行

  1. 启动mysql-shell
mysqlsh
  1. 连接主库
mysql-js> shell.connect('root@master:3306')
  1. 获取集群
mysql-js> var cluster=dba.getCluster('onlineCluster') // 用cluster变量接收集群
  1. 查看集群状态
mysql-js> cluster.status()

# 展示内容如下:
{
    "clusterName": "myCluster",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "master:3306",
        "status": "OK_NO_TOLERANCE",
        "statusText": "Cluster is NOT tolerant to any failures.",
        "topology": {
            "master:3306": {
                "address": "master:3306",
                "mode": "R/W",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            },
            "slave1:3306": {
                "address": "slave1:3306",
                "mode": "R/O",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            }
        }
    }
}
  1. 切换主节点
mysql-js> cluster.setPrimaryInstance('root@slave1:3306') // 记忆中的
# 切回
mysql-js> cluster.setPrimaryInstance('root@master:3306')