Mysql傳統複製空庫搭建過程中reset slave以及reset slave all對複製的影響
阿新 • • 發佈:2018-11-19
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
- 空庫搭建主從
操作過程
主庫上操作
- 賦予複製賬戶:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.1.128' IDENTIFIED by 'repl';
- 檢視master資訊:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000022 | 612 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
從庫上操作
- 直接指定新的master:
[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;
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.
#報錯是因為128這臺mysql server之前是使用gtid複製指向另一臺mysql主庫;而且沒有經過reset slave清理相關資料,直接指向新的master肯定也會有問題。
- 關閉gtid設定:
[[email protected]-192-168-1-128 ~]# service mysql stop
Shutting down MySQL.... SUCCESS!
[[email protected]-192-168-1-128 ~]# vim /etc/my.cnf 在配置檔案中關閉gtid
#gtid-mode=on # GTID only
#enforce-gtid-consistency=true # GTID only
或者
enforce_gtid_consistency=OFF
gtid_mode=OFF
[[email protected]-192-168-1-128 ~]# service mysql start
Starting MySQL.. SUCCESS!
- 重新指定master,並開啟slave:
[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;
Query OK, 0 rows affected, 2 warnings (0.03 sec)
[email protected] : (none) 05:20:21> start slave;
ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
[email protected] : (none) 05:20:37> reset slave;
Query OK, 0 rows affected (0.03 sec)
[email protected] : (none) 05:20:56> start slave;
Query OK, 0 rows affected (0.10 sec)
- 檢視複製情況:
[email protected] : (none) 05:20:57> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.21
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000022
Read_Master_Log_Pos: 612
Relay_Log_File: mysql-relay-bin.000005
Relay_Log_Pos: 333
Relay_Master_Log_File: mysql-bin.000022
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: 1008
Last_Error: Error 'Can't drop database 'sbtest'; database doesn't exist' on query. Default database: 'sbtest'. Query: 'drop database sbtest'
Skip_Counter: 0
Exec_Master_Log_Pos: 154
Relay_Log_Space: 964
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path: