MySQL傳統複製和GTID複製參考
1.mysqldump或者xtrabackup匯出資料庫scp到需要需要的備庫上,然後倒入到資料庫中,本例子使用mysqldump,xtrabacup請參考另外部落格
http://blog.51cto.com/1937519/2283779
mysqldump -uroot -p --single_transaction --master-data=2 --databases app app1 data > all_db.sql
source all_db.sql
2.新增備庫:
檢視dump檔案有關複製的資訊:
-- GTID state at the beginning of the backup
SET @@GLOBAL.GTID_PURGED='08a7bcf7-a8e4-11e8-8b61-0800278f64de:1-438374';
-- Position to start replication or point-in-time recovery from
-- CHANGE MASTER TO MASTER_LOG_FILE='binlog.000064', MASTER_LOG_POS=715;
如果使用xtrabackup備份,可以檢視xtrabackup_info檔案獲得相應的gtid資訊。
第一種方法,傳統的方法:
CHANGE MASTER TO MASTER_HOST='192.168.56.101',MASTER_PORT=3306,MASTER_USER='repluser',MASTER_PASSWORD='MYsql#123',MASTER_LOG_FILE='binlog.000064',MASTER_LOG_POS=715;
第二種方法,使用gtid:
步驟:
a.reset master;
b.SET @@GLOBAL.GTID_PURGED='08a7bcf7-a8e4-11e8-8b61-0800278f64de:1-438374';
c.CHANGE MASTER TO MASTER_HOST='192.168.56.101', MASTER_PORT=3306,MASTER_USER='repluser',MASTER_PASSWORD='MYsql#123',MASTER_AUTO_POSITION = 1;
以下為reset master和GTID_PURGED前後的gtid變化情況:
檢視現在資料庫中gtid資訊:
mysql> show variables like '%gtid%';
+----------------------------------+-----------------------------------------------+
| Variable_name | Value |
+----------------------------------+-----------------------------------------------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed_compression_period | 1000 |
| gtid_mode | ON |
| gtid_next | AUTOMATIC |
| gtid_owned | |
| gtid_purged | 08a7bcf7-a8e4-11e8-8b61-0800278f64de:1-436675 |
| session_track_gtids | OFF |
+----------------------------------+-----------------------------------------------+
mysql> reset master;
Query OK, 0 rows affected (0.02 sec)
mysql> show variables like '%gtid%';
+----------------------------------+-----------+
| Variable_name | Value |
+----------------------------------+-----------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed_compression_period | 1000 |
| gtid_mode | ON |
| gtid_next | AUTOMATIC |
| gtid_owned | |
| gtid_purged | |
| session_track_gtids | OFF |
+----------------------------------+-----------+
mysql> SET @@GLOBAL.GTID_PURGED='08a7bcf7-a8e4-11e8-8b61-0800278f64de:1-438374';
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%gtid%';
+----------------------------------+-----------------------------------------------+
| Variable_name | Value |
+----------------------------------+-----------------------------------------------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed_compression_period | 1000 |
| gtid_mode | ON |
| gtid_next | AUTOMATIC |
| gtid_owned | |
| gtid_purged | 08a7bcf7-a8e4-11e8-8b61-0800278f64de:1-438374 |
| session_track_gtids | OFF |
+----------------------------------+-----------------------------------------------+
8 rows in set (0.01 sec)
CHANGE MASTER TO MASTER_HOST='192.168.56.101', MASTER_PORT=3306,MASTER_USER='repluser',MASTER_PASSWORD='MYsql#123',MASTER_AUTO_POSITION = 1;
start slave;
3.參考跳過複製錯誤:
傳統方法跳過事務:
stop slave;
set global sql_slave_skip_counter=1;
start slave;
show slave status\G;
使用gtid跳過事務:
stop slave;
set gtid_next='xxxxxxxxxxxxx:n';
begin;
commit;
set gtid_next='AUTOMATIC';
start slave;