mysql高可用命令关于从的命令半同步开关状态查询从的同步状态的核心参数查看读写状态从指向主关于主的命令查看主的应答数设置新主属性设置原始主属性主从半同步关系建立,检查主是否设置正确业务逻辑判断最新从的逻辑关于从的命令半同步开关状态查询SHOW STATUS like Rpl_semi_sync_slave_status结果为Variable_name || Value Rpl_semi_sync_slave_status || OFF从的同步状态的核心参数SHOW SLAVE STATUS #查询从的状态结果为Read_Master_Log_Pos || Second_Behind_Master || Master_log_File 主的binlog文件名 4 || 0 || mysql-bin.000002查看读写状态show global variables like read_only Variable_name || Value read_only || OFF #OFF表示开启写状态 ON表未只读状态打开读写权限set global read_only0 #读写开关打开从指向主CHANGE MASTER TO MASTER_HOST%S ,MASTER_PORT%d ,MASTER_AUTO_POSITION1;关于主的命令查看主的应答数show global variables like rpl_semi_sync_master_wait_for_slave_count Variable_name || Value rpl_semi_sync_master_wait_for_slave_count || 1设置应答数的SQL语法set globalrpl_semi_sync_master_wait_for_slave_count?设置新主属性stop slave #停止从 reset slave all #重置从的所有信息 set global read_only0 #读写开关打开 set global sync_binlog1 #设置双一操作 set global innodb_flush_log_at_trx_commit1设置原始主属性第一步在master上设置mysqlsync同步数据的用户create user mysqlsyncxxxipxxx(如果放行所有使用%)xxx identified by mysqlsync; #创建mysql同步用户 mysql grant replication slave on *.* to mysqlsync% identified by mysqlsync; show master status; 查看主库的状态 不要关闭窗口先 不要重启 ------------ 例如放行所有IP create user mysqlsync% identified by mysqlsync; mysql grant replication slave on *.* to mysqlsync% identified by mysqlsync; 例如放行指定IP create user mysqlsync197.0.96.94 identified by mysqlsync; mysql grant replication slave on *.* to mysqlsync197.0.96.94 identified by mysqlsync;第二步 在主上也查一下show slave statusshow slave status; ##看看原始的主是否有属性 reset slave all #清掉所有的slave status change master to master_host127.0.0.1,master_usermysqlsync,master_passwordmysqlsync,master_port3306第三步 这时主降为从时,可以直接使用命令,而不用加上用户名密码了change master to master_host%s,master_port%d,master_auto_position1主从半同步关系建立,检查主是否设置正确show global status like Rpl_semi_sync_master_clients ; #查看主的半同步从的应答数 2 show global status like Rpl_semi_sync_master_status ; #查看主的半同步状态是否打开 ON||OFF业务逻辑判断最新从的逻辑1.先比较Master_log_File的后缀2.再比较Read_Master_log_Pos 的最大位点信息3.再比较Seconds_Behind_Master的延迟秒数