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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 在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
目录
相关文章
|
2月前
|
SQL 关系型数据库 MySQL
MySQL主从复制
MySQL主从复制
35 0
|
1月前
|
关系型数据库 MySQL Java
MySQL的主从复制 && SpringBoot整合Sharding-JDBC解决读写分离
MySQL的主从复制 && SpringBoot整合Sharding-JDBC解决读写分离
39 0
|
1月前
|
SQL 关系型数据库 MySQL
MySQL中主从复制的原理和配置命令
要原因包括提高性能、实现高可用性、数据备份和灾难恢复。了解两大线程( I/O 和 SQL)I/O线程:目的:I/O线程主要负责与MySQL服务器之外的其他MySQL服务器进行通信,以便复制(replication)数据。 功能: 当一个MySQL服务器作为主服务器(master)时,I/O线程会将变更日志(binary log)中的事件传输给从服务器(slave)。从服务器上的I/O线程负责接收主服务器的二进制日志,并将这些事件写入本地的中继日志(relay log)。 配置: 在MySQL配置文件中,你可以通过配置参数如和来启用二进制日志和指定服务器ID。log-bin server
MySQL中主从复制的原理和配置命令
|
1月前
|
负载均衡 容灾 关系型数据库
mysql主从复制
mysql主从复制
44 1
|
4天前
|
SQL canal 运维
MySQL高可用架构探秘:主从复制剖析、切换策略、延迟优化与架构选型
MySQL高可用架构探秘:主从复制剖析、切换策略、延迟优化与架构选型
|
6天前
|
运维 负载均衡 关系型数据库
MySQL高可用解决方案演进:从主从复制到InnoDB Cluster架构
MySQL高可用解决方案演进:从主从复制到InnoDB Cluster架构
|
13天前
|
设计模式 容灾 关系型数据库
MySQL 主从复制架构
MySQL 主从复制架构
|
18天前
|
关系型数据库 MySQL Linux
【mysql】MySql主从复制,从原理到实践!
【mysql】MySql主从复制,从原理到实践!
30 0
|
20天前
|
SQL 关系型数据库 MySQL
Mysql主从复制
Mysql主从复制
|
1月前
|
SQL 关系型数据库 MySQL
mysql主从复制
mysql主从复制

推荐镜像

更多