当前位置:网站首页>MySQL master-slave replication

MySQL master-slave replication

2022-07-07 12:57:00 LC181119

1. Master slave replication architecture and principle

1.1MySQL Master-slave replication of

  • Read / write separation
  • Copy : Each node has the same data set , To expand outward , One way replication based on binary logs

1.2 The replication of

  • Load balanced read operations
  • Backup
  • High availability and fail over
  • The data distribution
  • MySQL upgrade

1.3 Replication Architecture

One master and one slave replication architecture

  One master multi slave replication Architecture

1.4 Master slave replication principle

Master slave copy related threads
  • Master node :
        dump Thread: For each Slave Of I/O Thread Start a dump Threads , Used to send to it binary log         events
  • From the node :
        I/O Thread: towards Master Request binary log events , And saved in the relay log
        SQL Thread: Read log events from the relay log , Replay locally

  1.5 Master slave replication features

  • Asynchronous replication : Good client performance
  • Inconsistency between master and slave data is common

2. Implement master-slave replication configuration

2.1 Master configuration :

(1) Enable binary logging
[mysqld]
server-id=#          # Recommended setting is ip The last digit of the address 
log_bin
(2) Set a globally unique node for the current node ID Number
[mysqld]
server-id=#          # Recommended setting is ip The last digit of the address 
log-basename=master  # optional , Set up datadir Log name in , Make sure you don't rely on host names 
explain :
server-id Value range of
1 to 4294967295 (>= MariaDB 10.2.2), The default value is 1
0 to 4294967295 (<= MariaDB 10.2.1), The default value is 0, If the slave node is 0, all master Will reject this slave The connection of

 (3) View and copy from the file and location of the binary log

SHOW MASTER STATUS;
(4) Create a user account with copy permission
GRANT REPLICATION SLAVE  ON *.* TO 'repluser'@'HOST' IDENTIFIED BY 'replpass';
#MySQL8.0  In two steps 
mysql> create user [email protected]'10.0.0.%' identified by '123456';
mysql> grant replication slave on *.* to [email protected]'10.0.0.%';

2.2 From node configuration :

(1) Start relay log
[mysqld]
server_id=#                        # Set a global only... For the current node ID Number 
log-bin
read_only=ON                       # Set database read-only , in the light of supper user Invalid 
relay_log=relay-log                #relay log File path , The default value is hostname-relay-bin
relay_log_index=relay-log.index    # The default value is hostname-relay-bin.index
(2) Connect to the master server using a user account with copy permission , And start the replication thread
CHANGE MASTER TO
  MASTER_HOST='10.0.0.8',
  MASTER_USER='repluser',
  MASTER_PASSWORD='123456',
  MASTER_PORT=3306,
  MASTER_LOG_FILE='mariadb-bin.xxxxxx',
  MASTER_LOG_POS=#;

原网站

版权声明
本文为[LC181119]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130616434011.html