手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

MySQL 5.6主从复制第二部分[恢复某一台从服务器]

[日期:2013-04-14] 来源:zhaokunyao.com  作者:Linux [字体:大 中 小]

可以看到Executed_Gtid_Set里面多了一个 4f65e570-7b32-11e2-a0de-00241db92e69:1

考虑如何进行恢复。
比较靠谱的办法是不操作主服务器, 导出从服务器green的数据,然后再导入blue中。

green:

MySQL [localhost] {msandbox} (test) > stop slave;
 
mysql [localhost] {msandbox} (test) > FLUSH TABLES WITH READ LOCK;
Query OK, 0 ROWS affected (0.00 sec)

从green导出数据,端口是5612

[root@H209 msb_5_6_10_b]# /home/modify/mysql/5.6.10/bin/mysqldump -uroot -p -h127.0.0.1 -P5612 --all-databases  --triggers --routines --events >all.sql 
Enter password: 
[root@H209 msb_5_6_10_b]#

green:

mysql [localhost] {msandbox} (test) > UNLOCK TABLES;
Query OK, 0 ROWS affected (0.00 sec)
mysql [localhost] {msandbox} (test) > START slave;

把数据导入blue,端口为5611

[root@H209 msb_5_6_10_b]# /home/modify/mysql/5.6.10/bin/mysql -uroot -p -h127.0.0.1 -P5611 < all.sql
Enter password: 
ERROR 1840 (HY000) at line 24: GTID_PURGED can only be set when GTID_EXECUTED is empty.

额…出错了..
all.sql:

  21 -- GTID state at the beginning of the backup 
  22 --
  23 
  24 SET @@GLOBAL.GTID_PURGED='05b47d41-7b10-11e2-9fff-00241db92e69:1-19';
  25

blue:

mysql [localhost] {msandbox} (test) > SHOW global VARIABLES LIKE '%GTID%';
+--------------------------+-----------------------------------------------------------------------------------+
| Variable_name            | VALUE                                                                             |
+--------------------------+-----------------------------------------------------------------------------------+
| enforce_gtid_consistency | ON                                                                                |
| gtid_executed            | 05b47d41-7b10-11e2-9fff-00241db92e69:1-19,
4f65e570-7b32-11e2-a0de-00241db92e69:1 |
| gtid_mode                | ON                                                                                |
| gtid_owned               |                                                                                   |
| gtid_purged              | 05b47d41-7b10-11e2-9fff-00241db92e69:1-15                                         |
+--------------------------+-----------------------------------------------------------------------------------+
5 ROWS IN SET (0.00 sec)

确实gtid_executed非空。

blue:

mysql [localhost] {msandbox} (test) > SET global gtid_executed='';
ERROR 1238 (HY000): Variable 'gtid_executed' IS a READ ONLY variable

这里困扰了我很久…
翻了文档才找到办法:

gtid_executed:
WHEN used WITH global scope, this variable contains a representation OF the SET OF ALL transactions that are logged IN the BINARY log. 
WHEN used WITH SESSION scope, it contains a representation OF the SET OF transactions that are written TO the cache IN the CURRENT SESSION.
Issuing RESET MASTER causes the global VALUE (but NOT the SESSION VALUE) OF this variable TO be reset TO an empty string.

需要reset master.

blue:

mysql [localhost] {msandbox} (test) > reset master;
Query OK, 0 ROWS affected (0.00 sec)

继续把数据导入blue,端口为5611

[root@H209 msb_5_6_10_b]# /home/modify/mysql/5.6.10/bin/mysql -uroot -p -h127.0.0.1 -P5611 < all.sql
Enter password: 
[root@H209 msb_5_6_10_b]#

继续复制:
blue

mysql [localhost] {msandbox} (test) > START slave;
Query OK, 0 ROWS affected, 1 warning (0.01 sec)

在slave上面做reset master…看起来比较怪异,但很管用。

linux
相关资讯       MySQL 5.6  MySQL 5.6主从复制 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款