mysql slave 切换_Mysql Slave群切换Master(转)

March 3, 2008 – 10:57 am

测试环境:

Type           OS               Mysql

Master        rhel3.5           5.1.22-rc-log

Slave1       rhel3.5           5.1.22-rc-log

Slave2        rhel4.4           5.1.22-rc-log

切换测试过程是:1) Master down

2) Slave1 切换成新的Master

3) Slave2 更换Master配置为原Slave2

详细过程如下:

1、从slave(slave1)群众中选定一个slave,准备钱换成master;

2、检查slave1的复制状态:

mysql> SHOW PROCESSLIST ;

+—-+————-+———–+——+———+————+———————————————————————–+——————+

| Id | User        | Host      | db   | Command | Time       | State                                                                 | Info             |

+—-+————-+———–+——+———+————+———————————————————————–+——————+

| 1 | system user |           | NULL | Connect |      54733 | Waiting for master to send event                                      | NULL             |

| 2 | system user |           | NULL | Connect | 4294965772 | Has read all relay log; waiting for the slave I/O thread to update it | NULL             |

| 8 | root        | localhost | NULL | Query   |          0 | NULL                                                                  | SHOW PROCESSLIST |

+—-+————-+———–+——+———+————+———————————————————————–+——————+

这里主要是检测Slave1是否已经应用完从Master读取过来的在relay log中的操作,如果未应用完不能stop slave,否则数据肯定会有丢失。

3、停止slave1的slave进程,并reset称master:

mysql> STOP SLAVE ;

Query OK, 0 rows affected (0.00 sec)

mysql> RESET MASTER;

Query OK, 0 rows affected, 8 warnings (0.02 sec)

4、将slave 群中的其他slave(slave2)的Master切换成新的master(由原slave1reset成的):

1) 停slave进程:

mysql> stop slave;

Query OK, 0 rows affected (0.00 sec)

2) 更换master:

mysql> CHANGE MASTER TO

->   MASTER_HOST=’10.0.65.106′,

->     MASTER_USER=’repl’,

->     MASTER_PASSWORD=’slavepass’

-> ;

Query OK, 0 rows affected (0.00 sec)

3) 开启slave:

mysql> start slave;

Query OK, 0 rows affected (0.00 sec)

5、检查slave的状态:

mysql> show slave status \G

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

Slave_IO_State: Waiting for master to send event

Master_Host: 10.0.65.106

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000001

Read_Master_Log_Pos: 106

Relay_Log_File: oindeve-relay-bin.000002

Relay_Log_Pos: 251

Relay_Master_Log_File: mysql-bin.000001

Slave_IO_Running: Yes

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: 106

Relay_Log_Space: 408

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

1 row in set (0.00 sec)

6、最后变换实际数据监测新的复制是否能成功进行:

1) 在新的Master创建测试表:

mysql> create table t3 as select * from test;

Query OK, 100003 rows affected (0.11 sec)

Records: 100003 Duplicates: 0 Warnings: 0

mysql> show tables;

+—————-+

| Tables_in_test |

+—————-+

| t1             |

| t2             |

| t3             |

| test           |

+—————-+

4 rows in set (0.00 sec)

mysql> select count(*) from t3;

+———-+

| count(*) |

+———-+

|   100003 |

+———-+

1 row in set (0.00 sec)

2) 在slave2上面看是否已经复制过去:

mysql> show tables;

+—————-+

| Tables_in_test |

+—————-+

| t1             |

| t2             |

| t3             |

| test           |

+—————-+

4 rows in set (0.00 sec)

mysql> select count(*) from t3;

+———-+

| count(*) |

+———-+

|   100003 |

+———-+

1 row in set (0.00 sec)

7、到此确认复制正常,master切换完成。

注:整个切换测试过程时间较短,大家从每一步操作后面反馈的执行时间也可以看出,所需要的操作步骤也不太多。但是此测试并不是数据库整体环境在提供服务的压力环境下所测试进行的,该过程数据库整体环境较为空闲,所以目前还不敢确保在压力环境下也会如此的顺利,等后面还会找机会在有应用压力的情况下再测试。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值