mysql GTID主从复制 跳过复制错误

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 在mysqlGTID下,使用SET GLOBAL SQL_SLAVE_SKIP_COUNTER = n会产生如下错误ERROR 1858 (HY000): sql_slave_skip_counter can not be set when the server is running with @@GLOBAL.

在mysqlGTID下,使用

SET GLOBAL SQL_SLAVE_SKIP_COUNTER = n

会产生如下错误

ERROR 1858 (HY000): sql_slave_skip_counter can not be set when the server is running with @@GLOBAL.GTID_MODE = ON. Instead, for each transaction that you want to skip, generate an empty transaction with the same GTID as the transaction

根据报错提示,我们可以看到我们可以通过执行空事务来跳过复制错误

STOP SLAVE;
SET GTID_NEXT="7d72f9b4-8577-11e2-a3d7-080027635ef5:5";
BEGIN; COMMIT;
SET GTID_NEXT="AUTOMATIC";
START SLAVE;

但是当需要跳过的事务较多时,这个方法比较麻烦。可以使用MySQL Utilities中的mysqlslavetrx跳过错误
mysqlslavetrx使用说明

mysqlslavetrx --gtid-set=87fd24be-683d-11e6-ba97-1418774c98d8:3-40 --slaves=root:beijing@localhost:/home/mysql/my3306.sock

参数说明:

 --dryrun

Execute the utility in dry-run mode, show the transactions (GTID) that would have been skipped for each slave but without effectively skipping them. This option is useful to verify if the correct transactions will be skipped.

 --gtid-set=<gtid-set>

Set of Global Transaction Identifiers (GTID) to skip.

 --help

Display a help message and exit.

 --license

Display license information and exit.

 --slaves=<slaves_connections>

Connection information for slave servers. List multiple slaves in comma-separated list.

To connect to a server, it is necessary to specify connection parameters such as the user name, host name, password, and either a port or socket. MySQL Utilities provides a number of ways to supply this information. All of the methods require specifying your choice via a command-line option such as --server, --master, --slave, etc. The methods include the following in order of most secure to least secure.

Use login-paths from your .mylogin.cnf file (encrypted, not visible). Example : <login-path>[:<port>][:<socket>]

Use a configuration file (unencrypted, not visible) Note: available in release-1.5.0. Example : <configuration-file-path>[:<section>]

Specify the data on the command-line (unencrypted, visible). Example : <user>[:<passwd>]@<host>[:<port>][:<socket>]

 --ssl-ca

The path to a file that contains a list of trusted SSL CAs.

 --ssl-cert

The name of the SSL certificate file to use for establishing a secure connection.

 --ssl-key

The name of the SSL key file to use for establishing a secure connection.

 --ssl

Specifies if the server connection requires use of SSL. If an encrypted connection cannot be established, the connection attempt fails. Default setting is 0 (SSL not required).

 --verbose, -v

Specify how much information to display. Use this option multiple times to increase the amount of information. For example, -v = verbose, -vv = more verbose, -vvv = debug.

 --version

Display version information and exit.

也可以通过

set global gtid_purged='887fd24be-683d-11e6-ba97-1418774c98d8:3-40';

跳过已经purge的部分,之后重新开启复制即可。
完成这些操作后,如果对数据一致性的问题有顾虑,可以通过 pt-table-checksum来进行一致性检查。

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
1月前
|
SQL 存储 关系型数据库
MySQL的主从复制&主从同步
MySQL的主从复制&主从同步
30 0
|
4月前
|
SQL 关系型数据库 MySQL
面试官:说一下MySQL主从复制的原理?
面试官:说一下MySQL主从复制的原理?
93 0
面试官:说一下MySQL主从复制的原理?
|
15天前
|
负载均衡 容灾 关系型数据库
mysql主从复制
mysql主从复制
31 1
|
1月前
|
SQL 存储 运维
MySQL高可用性:主从复制和集群
MySQL高可用性:主从复制和集群
36 0
|
14天前
|
SQL 关系型数据库 MySQL
mysql主从复制
mysql主从复制
|
1月前
|
SQL 网络协议 关系型数据库
【怒怼大厂面试官】听说你精通MySQL?来说说MySQL主从复制
面试官:MySQL主从复制了解吧?嗯嗯了解的。主要是利用了MySQL的Binary Log二进制文件。那我把二进制文件丢给从库,从库复制整个文件吗。噢噢不是的。
48 1
【怒怼大厂面试官】听说你精通MySQL?来说说MySQL主从复制
|
1月前
|
监控 负载均衡 关系型数据库
|
3月前
|
SQL 负载均衡 关系型数据库
MySQL(六)主从复制
MySQL(六)主从复制
27 0
|
3月前
|
关系型数据库 MySQL 数据库
史上最详细Docker部署Mysql主从复制,带每一步骤图!!!
史上最详细Docker部署Mysql主从复制,带每一步骤图!!!
159 2
|
4月前
|
关系型数据库 MySQL Java
(详解与使用)Sharding-JDBC通过mysql主从复制来进行项目优化
(详解与使用)Sharding-JDBC通过mysql主从复制来进行项目优化
33 0