MySQL 5.7 Master-slave replication
Https://dev.mysql.com/doc/refman/5.7/en/replication-gtids-howto.html
GTID (globaltransaction ID) is the number of a committed transaction and is a globally unique number. Gtid is actually made up of Uuid+tid. Where the UUID is the unique identity of a MySQL instance. The TID represents the number of transactions that have been committed on the instance and is monotonically incremented as the transaction commits.
Set Gtid mode, in the my.cnf inside the Mysqld tab inside the settings, after Setup, restart the MySQL service to take effect:
[Mysqld]
Gtid_mode=on
Log-slave-updates=on
Enforce-gtid-consistency=on
Mysql> Change Master to
master_host= ' main Library IP ',
Master_port= The main library port,
Master_user= ' Repl ',
master_password= ' repl password ',
master_auto_position=1;
mysql> start slave;
PS: Where there are differences, previously non-gtid is used master_log_file= ' mysql-bin.000009 ', master_log_pos=154, and Gtid adopted master_auto_positon=1; From the binlog of the Sync Master Library.
View copy status from library, yes double Yes, and seconds_behind_master:0:
The slave to use the master with GTID based transactions as the replication data source, and to use gtid-based auto-p Ositioning rather than file-based positioning. Issue a change MASTER to statement on the slave, including the master_auto_position option in the statement to tell the SL Ave that the master ' s transactions is identified by Gtids.
View standby Information
1. Main library show Slave hosts;
- SELECT * from INFORMATION_SCHEMA. Processlist WHERE COMMAND = ' Binlog Dump ';
View synchronization Status
1.Show slave Status\g
- SELECT service_state from Performance_schema.replication_connection_status;
Build a Cascade Backup library
- You need to set up Log_slave_updates=1 to make the repository generate Binlog
- Back up the database and build a new database from backup
- Synchronizing the new database with the standby library
Change the new database to synchronize with the main library
Reset slave;
Change Master to
master_host= ' main Library IP ',
Master_port= The main library port,
Master_user= ' Repl ',
master_password= ' repl password ',
Master_auto_position=1;
- Su-mysql
2. Login to the default (3306) Port instance
Source. Profile
mysql–uroot–p–h127.0.0.1–p3306
3. Login to the 3307 port instance
source. p3307
mysql–uroot–p–h127.0.0.1–p3307
Knowledge Point collation:
1.. mysql_history file records the commands executed by the MySQL user, there is a security risk and requires soft connection processing. Lns-l/dev/null $HOME/.mysql_history
2, MySQL how to build semi-synchronous and asynchronous standby library.
3. Installation of MySQL environment. Note Modify the owner, VIP configuration of the/relay_log folder.
4 MySQL 5.7 High Availability