设为首页 收藏本站
查看: 732|回复: 0

[经验分享] Mysql 主从同步问题总结

[复制链接]

尚未签到

发表于 2018-9-28 13:35:43 | 显示全部楼层 |阅读模式
  问题 1
  master:
  mysql> delete from test2;
  Query OK, 419431 rows affected (0.00 sec)
  mysql> insert into test2 select * from test_no_myisam;
  Ctrl-C -- sending "KILL QUERY 10" to server ...
  Ctrl-C -- query aborted.
  ERROR 1317 (70100): Query execution was interrupted
  mysql>
  mysql> select count(1) from test2;
  +----------+
  | count(1) |
  +----------+
  | 919888 |
  +----------+
  1 row in set (0.00 sec)
  
  slave:
  
  mysql> select count(1) from test2;
  +----------+
  | count(1) |
  +----------+
  | 0 |
  
  
  mysql> show slave status\G;
  *************************** 1. row ***************************
  Slave_IO_State: Waiting for master to send event
  Master_Host: 192.168.8.199
  Master_User: rep1
  Master_Port: 3306
  Connect_Retry: 60
  Master_Log_File: binlog.000018
  Read_Master_Log_Pos: 631625681
  Relay_Log_File: relaylog.000044
  Relay_Log_Pos: 167918085
  Relay_Master_Log_File: binlog.000018
  Slave_IO_Running: Yes
  Slave_SQL_Running: No
  Replicate_Do_DB:
  Replicate_Ignore_DB: mysql
  Replicate_Do_Table:
  Replicate_Ignore_Table: discuz.cdb_sessions
  Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
  Last_Errno: 1317
  Last_Error: Query partially completed on the master (error on master: 1317) and was aborted. There is a chance that your master is inconsistent at this point. If you are sure that your master is ok, run this query manually on the slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE; . Query: 'update ucgh_userlogin set firstlogin=(select min(logdate) from ucgh_loginlogs1 where ucgh_loginlogs1.uid=ucgh_userlogin.uid and ucgh_loginlogs1.serverid=ucgh_userlogin.serverid) where ucgh_userlogin.firstlogin='0000-00-00''
  Skip_Counter: 0
  Exec_Master_Log_Pos: 622930512
  Relay_Log_Space: 176613857
  Until_Condition: None
  Until_Log_File:
  Until_Log_Pos: 0
  Master_SSL_Allowed: No
  Master_SSL_CA_File:
  Master_SSL_CA_Path:
  Master_SSL_Cert:
  Master_SSL_Cipher:
  Master_SSL_Key:
  Seconds_Behind_Master: NULL
  Master_SSL_Verify_Server_Cert: No
  Last_IO_Errno: 0
  Last_IO_Error:
  Last_SQL_Errno: 1317
  Last_SQL_Error: Query partially completed on the master (error on master: 1317) and was aborted. There is a chance that your master is inconsistent at this point. If you are sure that your master is ok, run this query manually on the slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE; . Query: 'update ucgh_userlogin set firstlogin=(select min(logdate) from ucgh_loginlogs1 where ucgh_loginlogs1.uid=ucgh_userlogin.uid and ucgh_loginlogs1.serverid=ucgh_userlogin.serverid) where ucgh_userlogin.firstlogin='0000-00-00''
  1 row in set (0.00 sec)
  
  ERROR:
  
  No query specified
  
  解决方法:
  mysql> slave stop;
  mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;
  ERROR 2006 (HY000): MySQL server has gone away
  No connection. Trying to reconnect...
  Connection id:    120
  Current database: *** NONE ***
  
  Query OK, 0 rows affected (0.00 sec)
  
  
  Query OK, 0 rows affected (0.00 sec)
  
  
  mysql> show slave status\G;
  
  *************************** 1. row ***************************
  Slave_IO_State: Waiting for master to send event
  Master_Host: 192.168.8.199
  Master_User: rep1
  Master_Port: 3306
  Connect_Retry: 60
  Master_Log_File: binlog.000018
  Read_Master_Log_Pos: 632099171
  Relay_Log_File: relaylog.000044
  Relay_Log_Pos: 167930769
  Relay_Master_Log_File: binlog.000018
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
  Replicate_Do_DB:
  Replicate_Ignore_DB: mysql
  Replicate_Do_Table:
  Replicate_Ignore_Table: discuz.cdb_sessions
  Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
  Last_Errno: 0
  Last_Error:
  Skip_Counter: 0
  Exec_Master_Log_Pos: 622943196
  Relay_Log_Space: 177087347
  Until_Condition: None
  Until_Log_File:
  Until_Log_Pos: 0
  Master_SSL_Allowed: No
  Master_SSL_CA_File:
  Master_SSL_CA_Path:
  Master_SSL_Cert:
  Master_SSL_Cipher:
  Master_SSL_Key:
  Seconds_Behind_Master: 7954
  Master_SSL_Verify_Server_Cert: No
  Last_IO_Errno: 0
  Last_IO_Error:
  Last_SQL_Errno: 0
  Last_SQL_Error:
  1 row in set (0.00 sec)
  
  ERROR:
  
  No query specified
  
  
  问题 2
  mysql slave不能同步Last_SQL_Error: Error ‘Duplicate entry ‘
  昨天一台mysql slave 重启后,出现了 Last_SQL_Error: Error 'Duplicate entry ' 错误,不能同步更新
  mysql> show slave status\G;
  *************************** 1. row ***************************
  Slave_IO_State: Waiting for master to send event
  Master_Host: 192.168.10.100
  Master_User: slave_user
  Master_Port: 3306
  Connect_Retry: 60
  Master_Log_File: mysql-bin.000773
  Read_Master_Log_Pos: 63325
  Relay_Log_File: server122-relay-bin.000002
  Relay_Log_Pos: 165661
  Relay_Master_Log_File: mysql-bin.000771
  Slave_IO_Running: Yes
  Slave_SQL_Running: No
  Replicate_Do_DB:
  Replicate_Ignore_DB:
  Replicate_Do_Table:
  Replicate_Ignore_Table:
  Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
  Last_Errno: 1062
  Last_Error: Error 'Duplicate entry '1438019' for key 'PRIMARY'' on query. Default database: 'otrs'. Query: 'INSERT INTO ticket (tn, title, create_time_unix, queue_id, ticket_lock_id, user_id, group_id, ticket_priority_id, ticket_state_id, ticket_answered, escalation_start_time, timeout, valid_id, create_time, create_by, change_time, change_by) VALUES ('2012061310001851', 'Your order ORD201205A000016 was bounced back', 1339585744, 44, 1, 43, 1, 3, 4, 0, 1339585744, 0, 1, current_timestamp, 43, current_timestamp, 43)'
  Skip_Counter: 0
  Exec_Master_Log_Pos: 41969067
  Relay_Log_Space: 625695
  Until_Condition: None
  Until_Log_File:
  Until_Log_Pos: 0
  Master_SSL_Allowed: No
  Master_SSL_CA_File:
  Master_SSL_CA_Path:
  Master_SSL_Cert:
  Master_SSL_Cipher:
  Master_SSL_Key:
  Seconds_Behind_Master: NULL
  Master_SSL_Verify_Server_Cert: No
  Last_IO_Errno: 0
  Last_IO_Error:
  Last_SQL_Errno: 1062
  Last_SQL_Error: Error 'Duplicate entry '1438019' for key 'PRIMARY'' on query. Default database: 'otrs'. Query: 'INSERT INTO ticket (tn, title, create_time_unix, queue_id, ticket_lock_id, user_id, group_id, ticket_priority_id, ticket_state_id, ticket_answered, escalation_start_time, timeout, valid_id, create_time, create_by, change_time, change_by) VALUES ('2012061310001851', 'Your order ORD201205A000016 was bounced back', 1339585744, 44, 1, 43, 1, 3, 4, 0, 1339585744, 0, 1, current_timestamp, 43, current_timestamp, 43)'
  1 row in set (0.00 sec)
  ERROR:
  No query specified
  
  解决的办法是:
  mysql> slave stop;
  mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
  mysql> slave start;
  我一般用上面那种方法(推荐),不过下面这种方法也可以:
  修改mysql配置文件 /etc/my.cnf 在 [mysqld]下加一行 slave_skip_errors = 1062 ,保存.重启mysql. mysql slave可以正常同步了.
  
  问题 3
  今天我们一个同事在操作数据库时,在主数据库插入了一个字段,以为没有插入成功,又在另外一台数据库上插入相同的字段,结果数据库主从出问题了。
  mysql> show slave status\G;
  *************************** 1. row ***************************
  Slave_IO_State: Waiting for master to send event
  Master_Host: 192.168.10.100
  Master_User: slave_user
  Master_Port: 3306
  Connect_Retry: 60
  Master_Log_File: mysql-bin.000773
  Read_Master_Log_Pos: 63325
  Relay_Log_File: server122-relay-bin.000002
  Relay_Log_Pos: 165661
  Relay_Master_Log_File: mysql-bin.000771
  Slave_IO_Running: Yes
  Slave_SQL_Running: No
  Replicate_Do_DB:
  Replicate_Ignore_DB:
  Replicate_Do_Table:
  Replicate_Ignore_Table:
  Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
  Last_SQL_Errno: 1060
  Last_SQL_Error: Error 'Duplicate column name 'agentpath'' on query. Default database: 'webgame'. Query: 'ALTER TABLE `ucgh_gameuser`  ADD `agentpath` VARCHAR(255) NULL AFTER `agentextcode`'
  Skip_Counter: 0
  Exec_Master_Log_Pos: 41969067
  Relay_Log_Space: 625695
  Until_Condition: None
  Until_Log_File:
  Until_Log_Pos: 0
  Master_SSL_Allowed: No
  Master_SSL_CA_File:
  Master_SSL_CA_Path:
  Master_SSL_Cert:
  Master_SSL_Cipher:
  Master_SSL_Key:
  Seconds_Behind_Master: NULL
  Master_SSL_Verify_Server_Cert: No
  Last_IO_Errno: 0
  Last_IO_Error:
  Last_SQL_Errno: 1060
  Last_SQL_Error: Error 'Duplicate column name 'agentpath'' on query. Default database: 'webgame'. Query: 'ALTER TABLE `ucgh_gameuser`  ADD `agentpath` VARCHAR(255) NULL AFTER `agentextcode`'
  1 row in set (0.00 sec)
  ERROR:
  No query specified
  
  解决的办法和上面的一样:
  mysql> slave stop;
  mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
  mysql> slave start;
  
  
  


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-603348-1-1.html 上篇帖子: linux apache mysql php (lamp) 下篇帖子: Mysql+ssh配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表