table of Contents:
[0] concept
A, GTID asynchronous replication (a master-slave) No data / data structures based on small
[1] environment
[2] mounted mysql utilities (herein, the tool mounting means)
[3] begin configuring
[3.1] # accounts ready to copy in the main repository
# [3.2] parameter configuration (master and slave are equipped)
# [3.3] to restart two MySQL
# [3.4] on the main library View binlog
# [3.5.1] use mysqlreplicate (mysql tool utilities) configuration command
# [3.5.2] arranged in a conventional manner using
# 3.6 [master] data from test (run on the main database)
[4] my other articles
[4.1] mysql GTID copy practice
[5] verification
[5.1] show slave status \ G to see if there is wrong
whether [5.2] verification of previously created users synchronized from
[5.3] to create a test in the main library View sync with the database table test cases
[5.4] show global variables like '% gtid% '; see gTID information
Second, based on the lossless semi-sync GTID (a master-slave) (mysql5.7) based on large amounts of data initialization
text:
[0] concept
[0.5] GTID copy (mysql in 5.6.2 and later began to support GTID):
【2.5.1】GTID(Global Transaction Identifiers)概念:
For a number of committed transactions, the unique number of the transaction, and is a globally unique number. GTID and transactions will be recorded in the binlog, used to identify the transaction.
GTID is used to replace the previous, conventional replication methods (binlog + position), mysql 5.6.2 start GTID support.
After mysql support GTID, a transaction in the cluster is no longer alone, at each node, if there is the case with the same identifier to avoid the same transaction, in the case of multiple occurrences of the same node.
(It can be understood as a preliminary model of the row, and the difference between the statement, the former do remember specifically what happened, which is a record position)
The most direct effect GTID appears that every thing has a sense of uniqueness in the cluster, replicate the line in terms relative to the higher data security, failover easier.
[0.5.2] Case explain simple concepts:
For example, when we 2 from a master, the master switch fails to go from DB1, then additional 2 machines, need to manually constructed from the master;
Specifically:
- use the main library in the traditional way down to re-build - the trouble spots: Binlog Postion name and location points of each machine is different, where the need to re-locate the file in the location where the Change Master to MASTER_HOST = 'xxx' , MASTER_USER = 'xxx', master_password = 'xxx', MASTER_PORT = 'xxx', MASTER_LOG_FILE = 'xxx', MASTER_LOG_POS = 'xxx'; - use GTID way down to re-build the main library - vantage point: each GTID on the machine are the same, which do not control the file, where the position and to be positioned automatically in accordance GTID Change Master to MASTER_HOST = 'XXX', MASTER_USER = 'XXX', master_password = 'XXX', MASTER_PORT = 'XXX ', master_auto_postion =. 1;
[0.5.3] GTID composition
GTID is server_uuid: Sequence_Number composition;
(1) server_uuid: mysql example is a global unique representation; stored in $ {datadir} /auto.cnf
(2) Sequence_Number: a transaction label is inside mysql, mysql instance does not repeat a sequence number (unique within the server guaranteed), said transaction number has been submitted in this example, and is incremented as the transaction commits.
(3) it was originally submitted in accordance with the transaction on GTID know which instance, to facilitate troubleshooting and switch
A, GTID asynchronous replication (a master-slave) No data / data structures based on small
[1] environment
Operating System: CentOS linux 7.5
Database Version: 5.7.24
Database schema: copy from the master, the master for the production of library, from the library and the master library for disaster recovery data backup server, the default traditional asynchronous replication.
Main Library IP: 192.168.1.203 Port: 3306
From the library IP: 192.168.1.204 Port: 3306
[2] mounted mysql utilities (herein, the tool mounting means)
cd /download
wget https://cdn.mysql.com/archives/mysql-utilities/mysql-utilities-1.6.5.tar.gz
tar xvf mysql-utilities-1.6.5.tar.gz
cd mysql-utilities-1.6.5
python setup.py build
python setup.py install
mysqldiff --version
No net, then go to the official website to download, the download = "Archives =" on the left navigation bar have MySQL Utilities
[3] begin configuring
# Core statement: mysqlreplicate --master = root @ localhost: 3306 --slave = root @ localhost: 3306 --rpl the User-RPL =: passwd
# [3.1 ] ready to copy account on the main library
create user 'rpl' @ ' . 192.168.1% 'IDENTIFIED by' 123456 ' ;
Grant Slave Replication to ON * *.' rpl'@'192.168.1.% ' ; flush privileges ; the SELECT the User, Host from the mysql.user;
# [3.2] parameter configuration (with both master and slave)
#replication_new log_bin = / MySQL / log / 3306 / MySQL-bin # open the binlog log_bin_index = / MySQL / log / 3306 / MySQL-bin.index binlog_format = Row binlog_rows_query_log_events = ON max_binlog_size = 2048 the bind-address = 0.0.0.0 the server_id = 2,013,306 # Note that this server_id from the library and main library must not be the same as expire_logs_days = 7 # binlog more than seven days of cleaning up innodb_support_xa = 1 binlog_cache_size = 1M log_bin_trust_function_creators = 1 # synchronization stored procedures, functions, triggers innodb_flush_log_at_trx_commit = 1 sync_binlog = 1 transaction- Read-committed = Isolation #slave Replication relay_log = / MySQL / log / 3306 / relaylog / MySQL-relay.log log-Slave-Updates. 1 = READ_ONLY. 1 = Slave-Parallel-Workers. 4 =
Slave-Parallel-type = LOGICAL_CLOCK
master_info_repository = table #master_info logged to mysql.slave_master_info relay_log_info_repository = Table #relay_log be recorded, mysql.slave_relay_log_info relay_log_recovery. 1 = slave_skip_errors = ddl_exist_errors slave_preserve_commit_order. 1 =
# parameter increased GTID
gtid_mode = ON
enforce_gtid_consistency = #on. 1: when finding sentence / when the transaction is not supported GTID, returns an error message
log-Slave-the Updates = 1
binlog_gtid_simple-Recovery = 1 # 5.7.6 following default is off, 5.7.6 above default is ON
# [3.3] to restart two MySQL
Service MySQL restart
# [ View binlog 3.4] on the main library
MySQL-uroot--p123456
Show master stauts; - record file_name and file_pos
# [3.5.1] use mysqlreplicate (mysql utilities tool) configuration command
in the slave and master from the library to establish a connection, so synchronization
# (1) from the library configuration (but enough to run on the main database, a plurality of so only need to run on the main database from the library)
mysqlreplicate --master = the root: [email protected]: 3306 --slave = root: [email protected]: 3306 --rpl- user = rpl: 123456 -b
# (2) test
# test test libraries are the same (the main library run)
mysqlreplicate --master = root: [email protected]: 3306 --slave = root: [email protected]: 3306 --rpl the User-RPL = : DB-123456 --test the testdb =
# checking replication (master-slave operation can be checked from the library)
mysqlrplcheck --master = the root: [email protected]: = the root --slave 3306: [email protected]: 3306 -s
# replicated data consistency checking
mysqlrplsync --master = root: [email protected]: 3306 --slave = root: [email protected]: 3306
# [3.5.2] use the traditional way configuration
- Use GTID way down to re-build the main library - vantage point: GTID on each machine are the same, do not control the file which, in the position where, according to GTID can be automatically positioned to Change Master MASTER_HOST = ' XXX ', MASTER_USER =' XXX ', master_password =' XXX ', MASTER_PORT =' XXX ', master_auto_postion =. 1;
# [3.6] main (run on the main database) from the test data
Create Database test1;
use test1;
Create Table test1 (ID int);
INSERT INTO test1 values (. 1), (2), (. 3);
the commit;
SELECT * from test1;
main library
From the library
Synchronization successful!
[4] my other articles
[4.1] mysql GTID copy practice: https://www.cnblogs.com/gered/p/11417019.html
[5] verification
[5.1] show slave status \ G to see if there is wrong
OK. Two threads started, Error words of the field without any problems.
[5.2] user verification created earlier for synchronization over
OK, no problem.
[5.3] to create a test database and test table in the main library View sync situation
# Create a test2 database, table and test2.test1 the Create Database test2; the Create the Table test2.test1 (the above mentioned id int); INSERT INTO test2.test1 values (1);
the commit; the SELECT * from test2.test1;
View from the library
select * from test2.test1;
OK verification is completed.
[5.4] show global variables like '% gtid%'; see GTID information
See if you can turn the figure out of the box is GTID latest transaction, you can view transaction synchronization from the master control.
Second, based on the lossless semi-sync GTID (a master-slave) (mysql5.7) based on large amounts of data initialization
[1] based on the large amount of data backed up from the core code library initialization
- using the backup initialization core code SET @TEMP_LOG_BIN = @@ the SESSION .SQL_LOG_BIN; SET @@ the SESSION .SQL_LOG_BIN = 0 ; SET @@ GLOBAL.GTID_PURGED = 'Backup Infomation apos GTID' ; - a core set @@ SESSION.SQL_LOG_BIN = @ TEMP_LOG_BIN;
[2] mysqldump backup and recovery achieved
[3] xtrabackup implement backup and recovery
Reference documents:
Detailed GTID: https://blog.csdn.net/wmq880204/article/details/53160078
Detailed GTID: https://blog.csdn.net/thundermeng/article/details/50401150