• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase
您的位置:首页 > 数据库 >Mysql > MySQL中主从复制重复键问题修复方法

MySQL中主从复制重复键问题修复方法

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-11

通过本文主要向大家介绍了mysql 主从复制,mysql主从配置,mysql主从,mysql主从复制原理,mysql主从同步等相关知识,希望本文的分享对您有所帮助

-------------------quote begin------------------------ 3. If you decide that you can skip the next statement from the master, issue the following statements: mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = n; mysql> START SLAVE; The value of n should be 1 if the next statement from the master does not use AUTO_INCREMENT or LAST_INSERT_ID(). Otherwise, the value should be 2. The reason for using a value of 2 for statements that use AUTO_INCREMENT or LAST_INSERT_ID() is that they take two events in the binary log of the master.

-------------------quote end------------------------

MySQL文档中的意思是当master传到slave的语句中要用到auto_increment,或者last_insert_id()时,需要skip两个event. 但实际情况并非如此

测试过程如下: 172.16.161.26 为master 172.16.161.15 为slave 同步c2cdb,初始状态ok

1. 在master上创建测试表

mysql> create table tmp_test_0208(id int not null auto_increment,name varchar(30),primary key(id)) engine=innodb;
Query OK, 0 rows affected (0.20 sec)

2, 在salve上insert 3条记录

mysql> insert into tmp_test_0208 values(1,'a'),(2,'b'),(3,'c');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from tmp_test_0208;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
3 rows in set (0.00 sec)

3, 在master上insert 3条记录

mysql> insert into tmp_test_0208(name) values('a'),('b'),('c');
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from tmp_test_0208;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
3 rows in set (0.00 sec)

4,  slave 的sql thread 中止

/usr/local/mysql/bin/mysql -uroot -pxxx c2cdb -s -e "show slave status\G" |egrep "Slave_IO_Running|Sl
ave_SQL_Running"
Slave_IO_Running: Yes
Slave_SQL_Running: No

5,  skip next statemate后start slave正常

mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1 ;
Query OK, 0 rows affected (0.00 sec)

mysql> slave start;
Query OK, 0 rows affected (0.00 sec)

/usr/local/mysql/bin/mysql -uroot -pxxx c2cdb -s -e "show slave status\G" |egrep "Slave_IO_Running|Sl
ave_SQL_Running"
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

slave端errlog如下: 070208 16:07:59[ERROR] Slave: Error 'Duplicate entry '1' for key 1' on query. Default database: 'c2cdb'. Query: 'insert into tmp_te st_0208(name) values('a'),('b'),('c')', Error_code: 1062

070208 16:07:59 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE  START". We stopped at log 'db_auction1-bin.000203' position 14215101

070208 16:09:59 [Note] Slave SQL thread initialized, starting replication in log 'db_auction1-bin.000203' at position 14215101, rela y log './db_auction1_b-relay-bin.000457' position: 200682931

 

master羰binlog中相应的记录如下:

# at 14215101 #070208 16:08:00 server id 1  log_pos 14215101  Intvar SET INSERT_ID=1; # at 14215129 #070208 16:08:00 server id 1  log_pos 14215129  Query   thread_id=2744782       exec_time=0     error_code=0 SET TIMESTAMP=1170922080; insert into tmp_test_0208(name) values('a'),('b'),('c');

总结:使用SET GLOBAL SQL_SLAVE_SKIP_COUNTER 命令跳过失败的SQL

</div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 深入mysql主从复制延迟问题的详解
  • mysql 复制过滤重复如何解决
  • mysql主从库不同步问题解决方法
  • Mysql 主从数据库同步(centos篇)
  • mysql主从服务器配置特殊问题
  • MYSQL主从库不同步故障一例解决方法
  • MySQL中主从复制重复键问题修复方法
  • MySQL主从复制配置心跳功能介绍
  • MySQL主从复制的原理及配置方法(比较详细)
  • MYSQL主从不同步延迟原理分析及解决方案

相关文章

  • 2018-12-05MySQL数据库报错:Too many connections的解决办法
  • 2018-12-05SQL学习笔记三 select语句的各种形式小结
  • 2018-12-05MySQL基本调度方法浅析
  • 2018-12-05关于gtid主从的8篇文章推荐
  • 2018-12-05sqlrun 权限设置好了,但启动不了,用本地的可以启动
  • 2018-12-05ORACLE常见错误代码的分析与解决三
  • 2018-12-05MySQL Event Scheduler(事件调度器)
  • 2018-12-05远程连接mysql数据库注意点记录
  • 2018-12-05详解Mysql数据库之Binlog日志使用代码总结
  • 2018-12-05SQL Server口令 sql server安全性第1/2页

文章分类

  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase

最近更新的内容

    • MySQL笔记之子查询使用介绍
    • sql 触发器使用例子
    • MySQL视图的应用之创建视图
    • mysql 让一个存储过程定时作业的代码
    • 一条SQL语句变得巨慢的原因及其解决方法
    • 总结Sql Server临时表和游标的使用方法
    • 详解RedHat6.5安装MySQL5.7教程(图文)
    • 多次执行mysql_fetch_array()的指针归位问题探讨
    • Can''t connect to MySQL server的解决办法
    • mysql 存储过程 1242-MySQL存储过程ITERATE和LEAVE

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有