search
HomeDatabaseMysql TutorialMySQL同步 1032,1062异常_MySQL

bitsCN.com

今天在MySQL同步中再次遇到了令人讨厌的 1062与1032错误。。

对于MySQL的replication,感觉有点不太靠谱,,我不知道其他DBA都是用哪些同步方案。

在思考是否需要换个同步方案,随着访问量的增加,一主一备看来也比较脆弱了。宕机风险也高。

先前态度比较乐观。根据错误的提示:

20131128_14:56:09mysql> show slave status/G;20131128_14:56:09*************************** 1. row ***************************20131128_14:56:09               Slave_IO_State: Waiting for master to send event20131128_14:56:09                  Master_Host: 192.168.101.21020131128_14:56:09                  Master_User: backup20131128_14:56:09                  Master_Port: 330620131128_14:56:09                Connect_Retry: 6020131128_14:56:09              Master_Log_File: mysql-bin.00147220131128_14:56:09          Read_Master_Log_Pos: 33932892420131128_14:56:09               Relay_Log_File: hostname-relay-bin.00451320131128_14:56:09                Relay_Log_Pos: 6663598520131128_14:56:09        Relay_Master_Log_File: mysql-bin.00147220131128_14:56:09             Slave_IO_Running: Yes20131128_14:56:09            Slave_SQL_Running: No20131128_14:56:09              Replicate_Do_DB: 20131128_14:56:09          Replicate_Ignore_DB: mysql,test20131128_14:56:09           Replicate_Do_Table: 20131128_14:56:09       Replicate_Ignore_Table: 20131128_14:56:09      Replicate_Wild_Do_Table: 20131128_14:56:09  Replicate_Wild_Ignore_Table: 20131128_14:56:09                   Last_Errno: 103220131128_14:56:09                   Last_Error: Could not execute Update_rows event on table feiliu_bbs.uc_member_info; Duplicate entry '20551928' fo20131128_14:56:09r key 'PRIMARY', Error_code: 1062; Can't find record in 'uc_member_info', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the ev20131128_14:56:09ent's master log mysql-bin.001472, end_log_pos 6663664620131128_14:56:09                 Skip_Counter: 020131128_14:56:09          Exec_Master_Log_Pos: 6663583920131128_14:56:09              Relay_Log_Space: 33933628120131128_14:56:09              Until_Condition: None20131128_14:56:09               Until_Log_File: 20131128_14:56:09                Until_Log_Pos: 020131128_14:56:09           Master_SSL_Allowed: No20131128_14:56:09           Master_SSL_CA_File: 20131128_14:56:09           Master_SSL_CA_Path: 20131128_14:56:09              Master_SSL_Cert: 20131128_14:56:09            Master_SSL_Cipher: 20131128_14:56:09               Master_SSL_Key: 20131128_14:56:09        Seconds_Behind_Master: NULL20131128_14:56:09Master_SSL_Verify_Server_Cert: No20131128_14:56:09                Last_IO_Errno: 020131128_14:56:09                Last_IO_Error: 20131128_14:56:09               Last_SQL_Errno: 103220131128_14:56:09               Last_SQL_Error: Could not execute Update_rows event on table feiliu_bbs.uc_member_info; Duplicate entry '20551928' fo20131128_14:56:09r key 'PRIMARY', Error_code: 1062; Can't find record in 'uc_member_info', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the ev20131128_14:56:09ent's master log mysql-bin.001472, end_log_pos 6663664620131128_14:56:09  Replicate_Ignore_Server_Ids: 20131128_14:56:09             Master_Server_Id: 1

发现时主键重复与更新失败。

主键重复的情况按照常理说可以直接跳过,所以我写好了命令:

命令1:stop slave sql_thread;set global sql_slave_skip_counter=1;start slave sql_thread;

Mysql 的Replication主要两个线程:1:IO_Thread 2:SQL_Thread;

网上都是建议直接stop slave或者start slave.这里主要是sql_thread的异常中断,所以我只重启sql_thread;

然后执行过命令1之后,发现这种情况不停的发生。不停的一次次跳过太过繁琐,通过问题来看主要是针对表

feiliu_bbs.uc_member_info

最终实在忍受不了,就打算从主库dump一份最新的数据到备份。于是我做了如下操作:

0:停止slave的同步进程

stop slave;

1:在master端手动备份目标表:uc_member_info,改名为uc_member_info_bak

create table uc_member_info_bak

select * from uc_member_info where 1=2;

2:导出表

mysqldump -uroot -p dbname tablename > tablename.sql

3:scp到备库,然后导入

mysql>source tablename.sql;

4:然后切换表名

切换之前,在新表uc_member_info_bak中补加原表uc_member_info 中的索引;

补加表中原有的索引:

create index idx_xxxx on uc_member_info_bak(cloumn_name);

切换表名:

alter table uc_member_info rename to uc_member_info_old;

alter table uc_member_info_bak rename to uc_member_info;

5:开启同步进程

start slave;

由于my.cnf中已经设置跳过主键重复错误。

slave-skip-errors = 1062


error错误日志中会不停弹出如下错误信息。

130922 12:23:20 [Warning] Slave SQL: Could not execute Write_rows event on table feiliu_bbs.uc_member_info; Duplicate entry '17564914' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.001185, end_log_pos 694223737, Error_code: 1062130922 12:23:21 [Warning] Slave SQL: Could not execute Write_rows event on table feiliu_bbs.uc_member_info; Duplicate entry '17564915' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.001185, end_log_pos 694274279, Error_code: 1062130922 12:23:21 [Warning] Slave SQL: Could not execute Write_rows event on table feiliu_bbs.uc_member_info; Duplicate entry '17564916' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.001185, end_log_pos 694278383, Error_code: 1062130922 12:23:21 [Warning] Slave SQL: Could not execute Write_rows event on table feiliu_bbs.uc_member_info; Duplicate entry '17564917' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.001185, end_log_pos 694326934, Error_code: 1062130922 12:23:21 [Warning] Slave SQL: Could not execute Write_rows event on table feiliu_bbs.uc_member_info; Duplicate entry '17564918' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.001185, end_log_pos 694340338, Error_code: 1062

弹出这个问题的原因是

备库现有的的uc_member_info是从主库dump过来的,比原有的备库表uc_member_info_old 进度要快。因为备库与主库之间存在较长时间的间隔,主库的binlog,在同步停止的时间内,没有及时发到备库导致。

解决方法:

首先停止同步,然后根据最后一条错误信息:

130922 12:23:21 [Warning] Slave SQL: Could not execute Write_rows event on table feiliu_bbs.uc_member_info; Duplicate entry '17564918' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.001185, end_log_pos 694340338, Error_code: 1062

删除 主键>=“17564918“的数据。因为主键为自增长。但是这个自增长不依赖自动序列。而上来源于另外一张表的主键。索引不用考虑自增序列的混乱情况。

删除之后,恢复同步。就不在出现主键重复的错误提示了。

等待同步,大约半个小时之后,仍然会出现1032错误。仍旧是表uc_member_info.现在怀疑应该不单单是单表的问题,而是数据库本身的一致性已经处理问题。准备放弃,进行重做。但是目前不能让备库停止,不能影响其他数据库的正常读取业务。故准备采用杀手锏!

准备进行设置数据库跳过一般的错误异常,使之不会轻易停止同步。

使用:slave_exec_mode参数

(具体参数说明 http://blog.csdn.net/zhangbiaobiaobiao/article/details/17072199 这里记录过大概。)

然后准备后续的主备的一致性验证与备份重做。



bitsCN.com
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you alter a table in MySQL using the ALTER TABLE statement?How do you alter a table in MySQL using the ALTER TABLE statement?Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

How do I configure SSL/TLS encryption for MySQL connections?How do I configure SSL/TLS encryption for MySQL connections?Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

How do you handle large datasets in MySQL?How do you handle large datasets in MySQL?Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you drop a table in MySQL using the DROP TABLE statement?How do you drop a table in MySQL using the DROP TABLE statement?Mar 19, 2025 pm 03:52 PM

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

How do you create indexes on JSON columns?How do you create indexes on JSON columns?Mar 21, 2025 pm 12:13 PM

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

How do you represent relationships using foreign keys?How do you represent relationships using foreign keys?Mar 19, 2025 pm 03:48 PM

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?Mar 18, 2025 pm 12:00 PM

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.