创建GTID主从连接:

  1. mysql> change master to master_host='master_id', master_port=3306, master_user='user', master_password='password', master_auto_position=1;

报错显示:

  1. Slave_IO_Running: Yes
  2. Slave_SQL_Running: No
  3. Last_Error: Error 'Can't drop database 'test'; database doesn't exist' on query. Default database: 'test'. Query: 'drop database test'
    Retrieved_Gtid_Set: 988b8684-3e21-22e6-a801-24505689c77d:1-9
    Executed_Gtid_Set: 

两个新实例启动后我预先做了一些安全处理,然后就直接在从库执行change master,导致主库上的日志在从库里执行不了,需要把无法执行的日志都跳过!

机械的搬运老师上课讲的内容如下:

  1. mysql> stop slave;
  2. Query OK, 0 rows affected (0.00 sec)
  3.  
  4. mysql> set gtid_next="988b8684-3e21-22e6-a801-24505689c77d:9";
  5. Query OK, 0 rows affected (0.00 sec)
  6.  
  7. mysql> begin;commit;
  8. Query OK, 0 rows affected (0.00 sec)
  9.  
  10. Query OK, 0 rows affected (0.01 sec)
  11.  
  12. mysql> set gtid_next="AUTOMATIC";
  13. Query OK, 0 rows affected (0.00 sec)
  14.  
  15. mysql> start slave;
  16. Query OK, 0 rows affected (0.00 sec)

结果

  1. mysql> show slave status\G
  2. *************************** 1. row ***************************
  3. Slave_IO_Running: Yes
  4. Slave_SQL_Running: No
  5. Last_Error: Error 'Can't drop database 'test'; database doesn't exist' on query. Default database: 'test'. Query: 'drop database test'
  6.  
  7. Retrieved_Gtid_Set: 988b8684-3e21-22e6-a801-24505689c77d:1-9

Executed_Gtid_Set: 988b8684-3e21-22e6-a801-24505689c77d:9

没起作用!这是什么问题?

再去查看主库上的binlog日志,查找drop database test相关的日志:

  1. # at 151
  2. #160630 1:55:19 server id 623306 end_log_pos 199 CRC32 0x5954bb4c GTID [commit=yes]
  3. SET @@SESSION.GTID_NEXT= '988b8684-3e21-22e6-a801-24505689c77d:1'/*!*/;
  4. # at 199
  5. #160630 1:55:19 server id 623306 end_log_pos 284 CRC32 0x6db10369 Query thread_id=1 exec_time=0 error_code=0
  6. SET TIMESTAMP=1467222919/*!*/;
  7. SET @@session.pseudo_thread_id=1/*!*/;
  8. SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
  9. SET @@session.sql_mode=1073741824/*!*/;
  10. SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
  11. /*!\C utf8 *//*!*/;
  12. SET @@session.character_set_client=83,@@session.collation_connection=83,@@session.collation_server=83/*!*/;
  13. SET @@session.lc_time_names=0/*!*/;
  14. SET @@session.collation_database=DEFAULT/*!*/;
  15. drop database test
  16. /*!*/;

问题找到了,drop database test对应的事务号是1,而不是顺序显示的9,接下来就简单了,重复上面的操作,但把事务号9改成1:

  1. mysql> stop slave;
  2. Query OK, 0 rows affected (0.00 sec)
  3.  
  4. mysql> set gtid_next="988b8684-3e21-22e6-a801-24505689c77d:1";
  5. Query OK, 0 rows affected (0.00 sec)
  6.  
  7. mysql> begin;commit;
  8. Query OK, 0 rows affected (0.00 sec)
  9.  
  10. Query OK, 0 rows affected (0.01 sec)
  11.  
  12. mysql> set gtid_next="AUTOMATIC";
  13. Query OK, 0 rows affected (0.00 sec)
  14.  
  15. mysql> start slave;
  16. Query OK, 0 rows affected (0.00 sec)

再有相似的报错也同样处理,最后终于没问题了:

  1. mysql> show slave status\G
  2. Slave_IO_Running: Yes
  3. Slave_SQL_Running: Yes
  4. Retrieved_Gtid_Set: 988b8684-3e21-22e6-a801-24505689c77d:1-9
  5. Executed_Gtid_Set: 988b8684-3e21-22e6-a801-24505689c77d:1-9

over

收获:知其然很重要,知其所以然更重要

要理解GTID代表的是什么,每个事务的提交都代表着一个GTID的生成,正如其全名:全局事务ID(global transaction identifier),所以如果想跳过导致错误的事务不执行的话,需要找到对应事务的gtid号,设置(set gtid_next="....")并提交空事务后重新启用自动模式后,再重启slave就可以,并不是每个导致错误的事务都是binlog中最后一个事务

另外,还要理解相关的参数:

  1. Retrieved_Gtid_Set
  2. The set of global transaction IDs corresponding to all transactions received by this slave. Empty if GTIDs are not in use.
  3. This is the set of all GTIDs that exist or have existed in the relay logs
  4.  
  5. IO线程接收到的日志
  1. Executed_Gtid_Set
  2. The set of global transaction IDs written in the binary log. This is the same as the value for the global gtid_executed system variable on this server, as well as the value for Executed_Gtid_Set in the output of SHOW MASTER STATUS on this server. Empty if GTIDs are not in use.
  3.  
  4. SQL线程执行到的位置

理解了这个后就能明白,之前的处理还是太复杂,其实直接看show slave satus\G的结果,看这两个参数的值:

  1. Slave_IO_Running: Yes
  2. Slave_SQL_Running: No
  3. Last_Error: Error 'Can't drop database 'test'; database doesn't exist' on query. Default database: 'test'. Query: 'drop database test'
  4. Retrieved_Gtid_Set: 988b8684-3e21-22e6-a801-24505689c77d:1-9
  5. Executed_Gtid_Set:

能够看到,Executed_Gtid_Set是空的,而且GTID是肯定开启了的,所以,说明日志传过来后压根还没开始执行,所以,第一个事务就已经被卡住了,首先应该跳过的事务号就是1,也不必再去看日志了

查资料过程中看到一个很好的GTID介绍文章,链接在此:http://mysqllover.com/?p=594

GTID复制报错处理:Last_Error: Error 'Can't drop database 'test'; database doesn't exist' on query的更多相关文章

  1. mysql5.7同步复制报错1060故障处理

    mysql5.7同步复制报错故障处理 # 报错 1060,具体如下Last_Errno: 1060Last_Error: Coordinator stopped because there were ...

  2. 解决FPDF报错:FPDF error: Not a JPEG file / FPDF error: Not a PNG file

    最近有个项目需要用到FPDF,但是输出的时候报错: FPDF error: Not a JPEG file: http://***/data/attachment/forum/201603/19/10 ...

  3. VS经常报错的link error 2019

    VS经常报错的link error 2019 原因如下: 可能是找得到头文件,但是相关的dll或者lib找不到,需要在配置里面添加相应的库文件. project=>configuration.. ...

  4. http报错之return error code:401 unauthorized

     http报错之return error code:401 unauthorized 依据HTTP返回码所表示的意思应该是未授权,没有输入账号和password,因此解决方法就直接在HTTP包里面 ...

  5. Heka 编译安装后 运行报错 panic: runtime error: cgo argument has Go pointer to Go pointer

    Heka 编译安装后 运行报错 panic: runtime error: cgo argument has Go pointer to Go pointer 解决办法: 1.  Start heka ...

  6. PHP编译安装报错:configure: error: mcrypt.h not found. Please reinstall libmcrypt

    我是在CentOS6.5安装php5.5.28这个版本,PHP编译代码如下: ./configure --prefix=/usr/local/php --with-config-file-path=/ ...

  7. mysql启动报错 mysql InnoDB: Error: could not open single-table tablespace file

    mysql启动不成功,报错 mysql InnoDB: Error: could not open single-table tablespace file innodb_force_recovery ...

  8. xtrabackup备份MySQL报错:InnoDB: Error number 24 means 'Too many open files'

    xtrabackup备份MySQL报错:InnoDB: Error number 24 means 'Too many open files' 1.使用xtrabackup备份MySQL时出现如下报错 ...

  9. Echarts 报错:Uncaught Error: [MODULE_MISS]"echarts/config" is not exists!

    每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code   问题: 报错:Uncaught Error: [MODULE_MISS]" ...

随机推荐

  1. UIProgressView-初识IOS

    好几天没更新了,学的时候太紧,没时间复习了都.今天刚好有时间,多更几个. 今天复习的是UIProgressView,我们常见使用在修改某些属性的时候经常用到,比如透明度,今天我们介绍一个简单的使用例子 ...

  2. jquery滚动到指定元素,模仿锚点

    html <div class="pd-nav"> <div class="n-item active"> 保险服务 <i> ...

  3. MongoDB学习笔记01

    MongoDB的设计理念:能从服务器端转移到驱动程序来做的事,就尽量转移. 文档是MongoDB的核心概念.多个键及其关联的值有序的放置在一起便是文档.每种编程语言表示文档的方法不太一样. 文档的键是 ...

  4. JS滚轮事件(mousewheel/DOMMouseScroll)了解

    已经没有了小学生时代过目不忘的记忆力了,很多自己折腾的东西.接触的东西,短短1年之后就全然不记得了.比方说,完全记不得获取元素与页面距离的方法(getBoundingClientRect),或者是不记 ...

  5. border-radius讲解2

    一:border-radius只有一个取值时,四个角具有相同的圆角设置,其效果是一致的: .demo { border-radius: 10px; } 其等价于: .demo{ border-top- ...

  6. 【转载】ADO.NET与ORM的比较(4):EntityFramework实现CRUD

    [转载]ADO.NET与ORM的比较(4):EntityFramework实现CRUD 说明:个人感觉在Java领域大型开发都离不了ORM的身影,所谓的SSH就是Spring+Struts+Hiber ...

  7. 0104.1——视图控制器UIViewController

    一.生命周期 当一个视图控制器被创建,并在屏幕上显示的时候. 代码的执行顺序1. alloc                              创建对象,分配空间2.init (initWit ...

  8. unity 打包 windows 运行 紫色 粉红色

    unity下建立了个小demo,在editer里面运行正常.如下 但是一旦打包发布到android或者windows下就出现了类似这种情况 这种一般是由于材质贴图的缺失,一般来说选定的默认贴图的话会打 ...

  9. cherry-pick,revert和rebase使用的3-way合并策略

    git中的cherry-pick,revert和rebase都使用的是3-way合并策略,下面就来看看这3个方法使用的merge-base,ours和theirs分别是什么. cherry-pick ...

  10. 用IBM WebSphere DataStage进行数据整合: 第 1 部分

    转自:http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0602zhoudp/ 引言 传统的数据整合方式需要大量的手工 ...