Configure MySQL master-slave replication

Configure MySQL master-slave replication

The master copy is MySQL from asynchronous operation.
MySQL master-slave replication
MySQL replication types are divided into two kinds:

  1. Log-based replication Binary Log
  2. Use GTID complete the transaction-based replication

Three kinds Binary Log log format:

  1. Statement: store SQL statements, the minimum amount of log storage
  2. Row: storing event data, store the log capacity, can not be directly read
  3. Mixed: between the Row and Statement, the operation for recording the Row uncertain

Log-based replication

Test environment
both equipped with a virtual machine CentOS7 where MySQL version 5.7.25
Master (primary) IP is 192.168.33.101
Slave (from) IP is 192.168.33.102

Configuration Master (primary)
used vim /etc/my.cnfto edit my.cnf, add the following configuration:

[mysqld]
server-id=1
log-bin=master-bin

After configuration is complete, you need systemctl restart mysqld.serviceto restart the service
by using the command show master statusView Master (main) Status:
 Master (primary) state
Creating a data synchronization users in the Master database, grant user permissions slave REPLICATION SLAVE, used data from the primary synchronization between the library.

CREATE USER 'slave'@'192.168.33.102' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'192.168.33.102';
FLUSH PRIVILEGES;

Configuring the Slave (from)
the same as adding configure Master my.cnf file as follows:

[mysqld]
server-id=2
relay-log=slave-relay-bin

After configuration is complete, you need systemctl restart mysqld.serviceto restart the mysql service configuration to take effect.

Connecting Master (primary) and the Slave (from)

Connected to the Slave (from) the database Master (Main):

change master to master_host='192.168.33.101', master_user='slave', master_password='123456', master_port=3306, master_log_file='master-bin.000001', master_log_pos=775;

parameter:

  • MASTER_HOST : Master Address
  • MASTER_PORT : Master port number
  • MASTER_USER : a user of the master-slave synchronization
  • master_password : a synchronization master password from the user
  • MASTER_LOG_FILE : specified log file
  • master_log_pos start reading location for the log file:

Master-slave synchronization start start slave;
viewing Slave (from) state:
View Slave (from) state
Slave_IO_Running and Slave_SQL_Running are Yes, explain the success of the master-slave replication configuration.

Test master-slave replication

Creating a database db_test the Master:
Master Database
At this point, see Slave database, found that has been automatically sync db_test:
Slave Database

reference

  1. MySQL5.7 replication combat
  2. Mysql based Docker's main building from copy

Guess you like

Origin blog.csdn.net/leifchen90/article/details/93775447