同一機器上三個實例,3307爲maser,新造兩個mariadb實例,端口分別爲3309 和3310,開始搭建複製關係,版本爲mariadb 10.0.10mysql
3307 導出: mysqldump --master-data=2
導入:
mysql -u -p --socket=/tmp/mysql3309.sock </apps/bak_3307.sql
mysql -u -p --socket=/tmp/mysql3310.sock </apps/bak_3307.sqlsql
dba@192.168.50.111(test_3309) : (none) 05:20:31>select @@global.gtid_current_pos; |
---|
@@global.gtid_current_pos |
0-501113309-31329 |
1 row in set (0.02 sec)app
dba@192.168.50.111(test_3309) : (none) 05:21:10>select @@global.gtid_current_pos; |
---|
@@global.gtid_current_pos |
0-501113309-32311 |
1 row in set (0.00 sec)socket
dba@192.168.50.111(test_3309) : (none) 05:21:33>SELECT @@GLOBAL.gtid_slave_pos; |
---|
@@GLOBAL.gtid_slave_pos |
1 row in set (0.00 sec)函數
能夠看出@@global.gtid_current_pos ,因爲數據不斷寫入,值是變的,而@@GLOBAL.gtid_slave_pos 因爲複製關係尚未搭建,目前是空值.code
mysqldump備份文件裏面的change master備註:-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000052', MASTER_LOG_POS=394894368;server
change master to master_host='192.168.50.111', MASTER_PORT=3307,master_user='', master_password='', master_log_file='mysql-bin.000052', master_log_pos=394894368;it
start slave
dba@192.168.50.111(test_3309) : (none) 07:22:21>select @@global.gtid_current_pos; |
---|
@@global.gtid_current_pos |
0-501113307-7227948 |
1 row in set (0.00 sec)event
dba@192.168.50.111(test_3309) : (none) 07:22:48>SELECT @@GLOBAL.gtid_slave_pos; |
---|
@@GLOBAL.gtid_slave_pos |
0-501113307-7227956 |
+-------------------------+ 能夠看到 @@GLOBAL.gtid_slave_pos 已經有值了,無論是否採用傳統或者gtid模式來複制.mariadb
STOP SLAVE;
CHANGE MASTER TO master_host="192.168.50.111", master_port=3307, master_user='', master_password='', master_use_gtid=current_pos;
START SLAVE;
show slave status G 增長內容:
Master_Server_Id: 501113307
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: Current_Pos
Gtid_IO_Pos: 0-501113307-7227969
在主庫上(3307)執行 : SELECT BINLOG_GTID_POS("mysql-bin.000052", 394894368); | |
---|---|
BINLOG_GTID_POS("mysql-bin.000052", 394894368) | |
0-501113307-7227451 | -- 獲得GTID位置 |
從庫上執行:
SET GLOBAL gtid_slave_pos = "0-501113307-7227451"; -- BINLOG_GTID_POS 函數獲得的位置
CHANGE MASTER TO master_host="192.168.50.111", master_port=3307, master_user='', master_password='', master_use_gtid=slave_pos;
START SLAVE;
show slave status G
Master_Server_Id: 501113307
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: Slave_Pos
Gtid_IO_Pos: 0-501113307-7228013
STOP SLAVE;
CHANGE MASTER TO master_host="192.168.50.111", master_port=3309
START SLAVE;
show slave status G
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.50.111
Master_User: rep
Master_Port: 3309
Master_Server_Id: 501113309
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: Slave_Pos
Gtid_IO_Pos: 0-501113307-7280903 -- 雖然切換到3309 ,gtid的server-id,仍是3307的,501113307
STOP SLAVE;
CHANGE MASTER TO master_host="192.168.50.111", master_port=3307
START SLAVE;
dba@192.168.50.111(test_3310) : (none) 03:29:42>show slave status G
1. row **
Slave_IO_State: Waiting for master to send event Master_Host: 192.168.50.111 Master_User: rep Master_Port: 3307 Connect_Retry: 60 Master_Log_File: mysql-bin.000052 --變回3307 端口的了 Read_Master_Log_Pos: 425706839 Master_Server_Id: 501113307 Master_SSL_Crl: Master_SSL_Crlpath: Using_Gtid: Slave_Pos Gtid_IO_Pos: 0-501113307-7281435 GTID的前兩段,不變,也就是全局惟一
select @@global.gtid_slave_pos, @@global.gtid_binlog_pos,@@global.gtid_current_pos;