目前我们在使用 Maxwell 在读线上机器的 binlog 同步我们的离线数据库。

这次错误定位上,首先线要确定问题是发生在生产者 还是队列 还是消费者。经过查看各机器上任务的运行日志,定位到了问题出在了任务的生产者上。

于是我试图去调看生产者上的 Maxwell 日志。之前一直跑得好好的 Maxwell 错误日志里面打出了这样一段内容:

17:53:24,420 INFO  OpenReplicator - starting replication at mysql-bin.000055:17870889
17:53:24,944 INFO TaskManager - stopping 3 tasks
17:53:24,944 ERROR TaskManager - cause:
com.zendesk.maxwell.schema.ddl.InvalidSchemaError: Couldn't find database 'remain_db'
at com.zendesk.maxwell.schema.Schema.findDatabaseOrThrow(Schema.java:52) ~[maxwell-1.10.3.jar:1.10.3]
at com.zendesk.maxwell.schema.ddl.TableCreate.resolve(TableCreate.java:34) ~[maxwell-1.10.3.jar:1.10.3]
at com.zendesk.maxwell.schema.ddl.TableCreate.resolve(TableCreate.java:13) ~[maxwell-1.10.3.jar:1.10.3]

可以看到 Maxwell 尝试去读 MySQL binlog.00055:17870889 这条 position 的内容是需要 find 一个叫 remain_db 的东西,由于没有 remain_db 所以这个行为失败了,导致整个同步的生产者卡住了。

排查这个问题我们需要知道一件事情,就是 Maxwell 会主动在被同步的数据库上面建立一个自己的数据库叫 Maxwell like this:

Maxwell 数据库里面会记录各种自己同步的时候会需要用到的信息,当他在同步到主数据库有建库建表相关 dll 的时候,他会使用相关语句在 自己的数据库把这些东西建出来。这里提示的找不到 remain_db 就是因为 Maxwell 自己数据库维护的 databases 表里面没有 remain_db 这个数据库的记录,所以就报错了。

正常维护的时候为啥会有漏掉的 DDL ? 仔细想想如果 binlog 没有出过问题是不应该发生这种情况的。所以如果着么思考的话应该很容易的定位到问题出在了 binlog 日志上面。后来我通过的 MySQL 的配置文件的查看配置的时候发现了问题所在,原来是我们数据库指定只同步了某一个数据库,但是之前有人在数据库 use 某个库的时候还执行了别的库的创建操作,导致这个创建行为的 DDL 被错误的同步到了 user 表的 binlog 上,也导致了这次错误。

发现了错误解决起来就相对容易了,由于错误信息以及 Maxwell 的数据表中都明确记录了 binlog 的中断位置,我只需要前往中断位置跳过相关语句就可以了。

具体的 binlog 查看操作命令可以参考 reference 里面的内容 这里只提几个最实用的,例如我会实用

mysqlbinlog   --start-position=205    --stop-position=314     mysql-bin.000001
来指定开始结束位置获取中间的 binlog 信息 我也可以使用 mysqlbinlog mysql-bin.0000001 | grep 'xxxx' 来获取我关注的信息

另外还可以在 mysql shell 里面使用类似语句:

show binlog events from 4 limit 2;

来查看指定 position 位置的以及指定多少条数来查看相关的 binlog 日志。

Reference:

http://soft.dog/2016/06/13/dig-mysql-binlog/#%E5%91%BD%E4%BB%A4%E6%B1%87%E6%80%BB  MySQL binlog 查看方法

排查 Maxwell can not find database 并且使用 MySQL binlog 解决相关问题的更多相关文章

  1. MySQL Binlog 解析工具 Maxwell 详解

    maxwell 简介 Maxwell是一个能实时读取MySQL二进制日志binlog,并生成 JSON 格式的消息,作为生产者发送给 Kafka,Kinesis.RabbitMQ.Redis.Goog ...

  2. 一次org.springframework.jdbc.BadSqlGrammarException ### Error querying database Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException问题排查过程

    先说结论: 因为在表设计中有一个商品描述字段被设置为desc,但desc是mysql中的关键字,如select id,name,desc,price from product;这条sql语句在查询时的 ...

  3. Database operations of Mysql

    update 表名 set 字段名=replace(同一个字段名,原字符串,新字符串);  --修改记录. 一.初始化 # cd /usr/local/mysql # chown -R mysql:m ...

  4. org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manu

    这个是sql 语句 错误     仔细检查 SQL语句是否写错了 org.apache.ibatis.exceptions.PersistenceException: ### Error queryi ...

  5. org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent succ

    数据库 没有开启  连接失败 org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause ...

  6. Error updating database. Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'as3'

    执行更新时的出错信息 Whitelabel Error Page This application has no explicit mapping for /error, so you are see ...

  7. [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up IDEA2019的database插件无法链接mysql的解决办法(08001错误)

    [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up. 点击这里 ...

  8. windows server2008 IIS下目录 [ application/database.php ] 不可写!解决

    windows server2008目录 [ application/database.php ] 不可写!解决     在服务器上找到网站根目录   网站用的thinkphp的框架   属性 -- ...

  9. go database/sql sql-driver/mysql 操作

    这里使用的是github.com/Go-SQL-Driver/MySQL, 所以需要下载一个github.com/Go-SQL-Driver/MySQL 引入 database/sql 和 githu ...

随机推荐

  1. centos7下安装docker(22.docker swarm-----service)

    运行service 执行以下命令: docker service create --name web-server httpd 通过docker service ls查看swarm中的service ...

  2. Springboot监控之一:SpringBoot四大神器之Actuator

    介绍 Spring Boot有四大神器,分别是auto-configuration.starters.cli.actuator,本文主要讲actuator.actuator是spring boot提供 ...

  3. git pull request 流程

    git pull request 用于在 fork 官方 repo 到个人 github, 在本地修改后,向官方 repo 请求合并.在官方团队审查过代码后,就可以将自己所做的改动合并到官方 repo ...

  4. ELMO模型(Deep contextualized word representation)

    1 概述 word embedding 是现在自然语言处理中最常用的 word representation 的方法,常用的word embedding 是word2vec的方法,然而word2vec ...

  5. 006_饿了么大前端总监sofish帮你理清前端工程师及大前端团队的成长问题!

    作者|Sofish编辑|小智 & 尾尾本文是前端之巅向 sofish 的约稿<什么样的人可以称为架构师?>.采访< 饿了么大前端团队究竟是如何落地和管理的?>以及 so ...

  6. (二 -3-3) 天猫精灵接入Home Assistant-自动发现Mqtt设备-自动生成配置信息

    http://www.hassmart.com/products/switches/#tab=config switch: - platform: mqtt name: keting state_to ...

  7. VS2017设置主题和代码字体

    从Visual Studio Marketplace下载主题插件 VS2017带有一个软件超市(Visual Studio Marketplace),可以和Eclipse一样从软件超市中下载各种插件, ...

  8. 【重磅干货整理】机器学习(Machine Learning)与深度学习(Deep Learning)资料汇总

    [重磅干货整理]机器学习(Machine Learning)与深度学习(Deep Learning)资料汇总 .

  9. 网盘直链工具 winform版 V1.0

    软件需要.net2.0支持 win7及以上版本用户无需安装 xp用户需要安装 支持网盘:好盘 坚果云 百度云 乐视云 华为网盘 微云 新浪网盘 126disk 速度盘 乐齐盘 天空网盘 千脑网盘 可乐 ...

  10. docker部署nginx

    1. 下载nginx [root@localhost my.Shells]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/ ...