主从复制错误处理总结

错误一

ERROR] Slave I/O: error connecting to master 'replication@VMS00782:3306' - retry-time: 60 retries: 2, Error_code: 1045

错误原因:从库用来连接主库的用户权限或者密码不对

解决方法:首先在主库上检查用来主从复制的用户权限,如果没有问题在检查从库使用的密码是否正确。

错误二

140331 10:08:18 [ERROR] Error reading master configuration140331 10:08:18 [ERROR] Failed to initialize the master info structure140331 10:08:18 [Note] Event Scheduler: Loaded 0 events

错误原因:这个可能是从库的master.info文件有损坏。

解决方法:reset slave

错误三

Error 'Duplicate entry '1' for key 1' on query. Default database: 'movivi1'. Query: 'INSERT INTO `v1vid0_user_samename` VALUES(null,1,'123','11','4545','123')'

错误原因:可能是从库的约束比主库更多写造成的。

解决方法:

Mysql > stop slave;Mysql > set global sql_slave_skip_counter =1 ;Mysql > start slave;

错误四

Slave SQL: Error 'Table 'xxxx' doesn't exist' on query. Default database: 't591'. Query: 'INSERT INTO `xxxx`(type,post_id,browsenum) SELECT type,post_id,browsenum FROM xxxx WHERE hitdate='20090209'', Error_code: 1146

错误原因:slave上缺少错误中的表。

解决方法:在slave上添加上对应的表,然后start slave。

错误五

Error 'Unknown column 'qdir' in 'field list'' on query. Default database: 'club'. Query: 'insert into club.question_del (id, pid, ques_name, givepoint, title, subject, subject_pid, createtime, approve, did, status, intime, order_d, endtime,banzhu_uid,banzhu_uname,del_cause,qdir) select id, pid, ques_name, givepoint, title, subject, subject_pid, createtime, approve, did, status, intime, order_d, endtime,'1521859','admin0523','无意义回复',qdir from club.question where id=7330212'1 row in set (0.00 sec)

错误原因:从库上对应的表上缺少字段。

解决方法:根据主库上表结构,在从库对应表上添加缺少的字段,然后start slave。

错误六

mysql> show slave status\G*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 192.168.60.159Master_User: backupMaster_Port: 3311Connect_Retry: 60Master_Log_File: mysql-bin.000012Read_Master_Log_Pos: 274863854Relay_Log_File: mysql-relay-bin.000007Relay_Log_Pos: 2160037Relay_Master_Log_File: mysql-bin.000012Slave_IO_Running: YesSlave_SQL_Running: NoReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 1146Last_Error: Error executing row event: 'Table 'panda.t' doesn't exist'Skip_Counter: 0Exec_Master_Log_Pos: 2159824Relay_Log_Space: 274866725

错误原因:主库删除的表在从库中不存在,导致从库在遇到删除不存在表的错误时无法继续同步。

解决方法:利用slave-skip-errors参数,跳过对于的1146错误(这个参数是一个只读的,需要在配置文件中修改,并重启从库)

1、在my.cnf的[mysqld]下面添加slave_skip_errors=1146
2、重启从库 service mysql restart

3、在从库上启动同步

mysql> start slave ;Query OK, 0 rows affected (0.01 sec)mysql> show slave status\G*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 192.168.60.159Master_User: backupMaster_Port: 3311Connect_Retry: 60Master_Log_File: mysql-bin.000012Read_Master_Log_Pos: 274863854Relay_Log_File: mysql-relay-bin.000007Relay_Log_Pos: 137439021Relay_Master_Log_File: mysql-bin.000012Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 137438808Relay_Log_Space: 274867275Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 88484Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 159Master_UUID: ded30ff9-62b2-11e6-b0d0-f80f41fa11bfMaster_Info_File: /usr/local/mysql-5.7.14-linux-glibc2.5-x86_64/data/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Reading event from the relay logMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec)

4、去掉my.cnf中的slave_skip_errors=1146

5、重启从库

6、启动从库复制
---------------------
原文:https://blog.csdn.net/gua___gua/article/details/52869614

(0)

相关推荐