1. 程式人生 > >Mysql傳統複製空庫搭建過程中reset slave以及reset slave all對複製的影響

Mysql傳統複製空庫搭建過程中reset slave以及reset slave all對複製的影響

Mysql傳統複製空庫搭建過程中reset slave以及reset slave all對複製的影響
主庫資訊
從庫資訊
操作過程
主庫上操作
從庫上操作
主庫上檢視
解決方法
思路探討
參考資料

Mysql傳統複製空庫搭建過程中reset slave以及reset slave all對複製的影響

主庫資訊

  • IP:192.168.1.21
  • 版本:5.7.18
  • 空庫搭建主從

從庫資訊

  • IP:192.168.1.128
  • 版本:5.6.36
  • 空庫搭建主從

操作過程

主庫上操作

  • 賦予複製賬戶:
  
  1. mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.1.128' IDENTIFIED by 'repl';
  • 檢視master資訊:
  
  1. mysql> show master status;
  2. +------------------+----------+--------------+------------------+-------------------+
  3. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
  4. +------------------+----------+--------------+------------------+-------------------+
  5. | mysql-bin.000022 | 612 | | | |
  6. +------------------+----------+--------------+------------------+-------------------+
  7. 1 row in set (0.00 sec)

從庫上操作

  • 直接指定新的master:
  
  1. [email protected] : (none) 05:16:09> change master to master_host='192.168.1.21',master_user='repl',master_password='repl',master_log_file='mysql-bin.000022',master_log_pos=612;
  2. ERROR 1776 (HY000): Parameters MASTER_LOG_FILE, MASTER_LOG_POS, RELAY_LOG_FILE and RELAY_LOG_POS cannot be set when MASTER_AUTO_POSITION is active.
  3. #報錯是因為128這臺mysql server之前是使用gtid複製指向另一臺mysql主庫;而且沒有經過reset slave清理相關資料,直接指向新的master肯定也會有問題。
  • 關閉gtid設定:
  
  1. [[email protected]-192-168-1-128 ~]# service mysql stop
  2. Shutting down MySQL.... SUCCESS!
  3. [[email protected]-192-168-1-128 ~]# vim /etc/my.cnf 在配置檔案中關閉gtid
  4. #gtid-mode=on # GTID only
  5. #enforce-gtid-consistency=true # GTID only
  6. 或者
  7. enforce_gtid_consistency=OFF
  8. gtid_mode=OFF
  9. [[email protected]-192-168-1-128 ~]# service mysql start
  10. Starting MySQL.. SUCCESS!
  • 重新指定master,並開啟slave:
  
  1. [email protected] : (none) 05:19:34> change master to master_host='192.168.1.21',master_user='repl',master_password='repl',master_log_file='mysql-bin.000022',master_log_pos=612;
  2. Query OK, 0 rows affected, 2 warnings (0.03 sec)
  3. [email protected] : (none) 05:20:21> start slave;
  4. ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
  5. [email protected] : (none) 05:20:37> reset slave;
  6. Query OK, 0 rows affected (0.03 sec)
  7. [email protected] : (none) 05:20:56> start slave;
  8. Query OK, 0 rows affected (0.10 sec)
  • 檢視複製情況:
  
  1. [email protected] : (none) 05:20:57> show slave status\G;
  2. *************************** 1. row ***************************
  3. Slave_IO_State: Waiting for master to send event
  4. Master_Host: 192.168.1.21
  5. Master_User: repl
  6. Master_Port: 3306
  7. Connect_Retry: 60
  8. Master_Log_File: mysql-bin.000022
  9. Read_Master_Log_Pos: 612
  10. Relay_Log_File: mysql-relay-bin.000005
  11. Relay_Log_Pos: 333
  12. Relay_Master_Log_File: mysql-bin.000022
  13. Slave_IO_Running: Yes
  14. Slave_SQL_Running: No
  15. Replicate_Do_DB:
  16. Replicate_Ignore_DB:
  17. Replicate_Do_Table:
  18. Replicate_Ignore_Table:
  19. Replicate_Wild_Do_Table:
  20. Replicate_Wild_Ignore_Table:
  21. Last_Errno: 1008
  22. Last_Error: Error 'Can't drop database 'sbtest'; database doesn't exist' on query. Default database: 'sbtest'. Query: 'drop database sbtest'
  23. Skip_Counter: 0
  24. Exec_Master_Log_Pos: 154
  25. Relay_Log_Space: 964
  26. Until_Condition: None
  27. Until_Log_File:
  28. Until_Log_Pos: 0
  29. Master_SSL_Allowed: No
  30. Master_SSL_CA_File:
  31. Master_SSL_CA_Path: