MySQL多主选举_mysql怎么选举出来一个新主

一主两从结构中,如果主库挂了,怎么选举出来一个新主

ip 192.168.0.110 3306(主)

ip 192.168.0.110 3307(从)

ip 192.168.0.110 3308(从)

模拟主库挂:

/usr/local/mysql/bin/mysqladmin -uroot -p -S /tmp/mysql3306.sock  shutdown

查看状态

s1:show slave status\G;

s2:show slave status\G;

root@localhost [test]>show slave status\G;

*************************** 1. row ***************************

Slave_IO_State: Reconnecting after a failed master event read

Master_Host: 192.168.0.110

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000001

Read_Master_Log_Pos: 619

Relay_Log_File: relay-bin.000002

Relay_Log_Pos: 832

Relay_Master_Log_File: mysql-bin.000001

Slave_IO_Running: Connecting

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 619

(1)首先s1和s2同步完成(Seconds_Behind_Master: NULL)

判断io_thread与sql_thread是否执行到同一个位置。

执行完成的依据为:

Master_Log_File == Relay_Master_Log_File  &&

Read_Master_Log_Pos == Exec_Master_Log_Pos

io_thread:

Master_Log_File: mysql-bin.000001

Read_Master_Log_Pos: 619

sql_thread:

Relay_Master_Log_File: mysql-bin.000001

Exec_Master_Log_Pos: 619

假设Master_Log_File==Relay_Master_Log_File但是

io.Read_Master_Log_Pos >sql.Exec_Master_Log_Pos

说明了什么?

说明relay-log没有应用完。

Slave_SQL_Running: Yes 2-5秒

(2)s1和s2 怎么选举出来一个

谁同步靠前,谁当主。

(-)

s1.Relay_Master_Log_File  == s2.Relay_Master_Log_File

s1.Exec_Master_Log_Pos == s2.Exec_Master_Log_Pos   选s1 或者s2都可以

如果s1.Relay_Master_Log_File  == s2.Relay_Master_Log_File 但是

s1.Exec_Master_Log_Pos > s2.Exec_Master_Log_Pos  选s1为主

(二)

同样也可以比较

s1.Master_Log_File==s2.Master_Log_File

s1.Read_Master_Log_Pos==s2.Read_Master_Log_Pos

(3)数据有没有差异怎么办?

出现数据不一致:

1、s1-->读和写全部接管,s2作为故障的从,最后用pt-table-checksum/pt-table-sync修复,在加起来。

old_master上的日志有没有安全传到slave上面???? MHA可以解决。

(4)GTID环境里面比较下面即可。

Retrieved_Gtid_Set: 6e5d664c-c7e5-11e6-88b1-000c296ae445:3

Executed_Gtid_Set: 6e5d664c-c7e5-11e6-88b1-000c296ae445:1-3

如果s1.GTID>s2.GTID

选new master为s1;把s2 change 到s1

(5)原来主库怎么办?

变成从库加进去。

主从故障修复 主从一致性检测、修复。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值