当前位置:网站首页>How to realize master-slave synchronization in mysql5.7
How to realize master-slave synchronization in mysql5.7
2022-07-27 05:47:00 【Code world of super Duoduo and Liu baobao】
List of articles
Preface
It was said before redis Master slave backup of :
Mysql Master-slave replication means that data can be copied from one Mysql Database nodes are replicated to multiple Mysql Database nodes . Mysql The database adopts asynchronous replication mechanism by default . So for master Nodes and slave Node , Only weak consistency can be guaranteed . May exist master Nodes and slave Inconsistent node data .
redis Synchronization: full synchronization for the first time ,slave take master Copy all the data on .slave Discard previous data , Will receive RDB All files are imported , Then perform incremental synchronization .
and redis Different ,mysql The master-slave synchronization can only be based on the synchronization of data operations after the setup , Unable to synchronize previous data , Therefore, manual synchronization is required
One 、 principle ?
1.master Node passing foke A thread records data changes to binlog In file
2.slave Node passing io Threads go every time master Node acquisition binlog Log data , Save to relay log In the relay log
3.slave The node detects that the relay log is updated ,sql The thread will synchronize the updated content to slave In nodes
tip: Remember the previous log listener ??
Two 、 step
1.master build
139.9.186.192 Server as master
1. Pull the mirror , Today pull 5.7 edition
docker pull mysql:5.7
2. function mysql-master
docker run -d -p 3306:3306 --name mysql-master -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7
3. Updates and Downloads vim plug-in unit
1.docker exec -it mysql-master /bin/bash
2.apt-get update
3.apt-get install vim
4. open my.cnf file
vim /etc/mysql/my.cnf
5. modify my.cnf file , Add the following file
[mysqld] // Required
server_id=1 // If you deploy a cluster under the same LAN , So many mysql Of server_id Cannot be the same
log-bin=mysql-bin // Log name
expire_logs_days=7 // Automatic cleaning log Time
6. restart mysql-master
7. See if it works
1. Get into docker exec -it mysql-master /bin/bash
2. Use mysql> mysql -u root -p
3.mysql> show variables like '%log_bin%'; //log_bin The log is on
8. Create users connected from the Library
mysql> grant replication slave on *.* to 'slave'@'%' identified by '123456';
9. View the status of the primary database
mysql> show master status // Record file Name and position Connect from the library later
2.slave build
1.15.233.184 by slave
1. Pull the mirror , PULL 5.7 edition
docker pull mysql:5.7
2. function mysql-master
docker run -d -p 3306:3306 --name mysql-slave -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7
3. Updates and Downloads vim plug-in unit
1.docker exec -it mysql-slave /bin/bash
2.apt-get update
3.apt-get install vim
4. open my.cnf file
vim /etc/mysql/my.cnf
5. modify my.cnf file
[mysqld]
server_id=2
read_only=1 // take slave Set the slave library to read only ,0 In read-write status
6. restart salve, Once again into the
7. Connect to mysql, Connect to master
mysql> change master to
-> master_host='139.9.186.192',
-> master_user='slave',
-> master_password='123456',
-> master_log_file='mysql-bin.000001', // Fill in what you are asked to record file
-> master_log_pos=406; // Fill in what you are asked to record position
mysql> start slave;
test :
from master Add one test database , that slave Will receive . If in slave add to , that master Will not receive 
边栏推荐
- 期货开户怎么选择好的期货公司 ?
- 「PHP基础知识」定界符的使用
- Promise's understanding and its instance method
- Web3流量聚合平台Starfish OS,诠释真正商业的“P2E”生态
- 机器人编程与交叉学科的融合延伸
- The main advantage of face brushing payment users is their high degree of intelligence
- 如果面试官问你 JVM,额外回答“逃逸分析”技术会让你加分
- Choose futures companies with state-owned enterprise background to open accounts
- Face brushing payment will never be out of date, but will continue to change
- inno setup 打包 jar + h5 + mysql + redis 成 exe
猜你喜欢
随机推荐
GameFi如何破圈,AQUANEE靠真正“P2E”展现风采
Characteristics of hexadecimal
「PHP基础知识」PHP中实现数学运算
You should negotiate the handling fee before opening a futures account
Sealem Finance - a new decentralized financial platform based on Web3
How to apply for the return of futures account opening company?
「PHP基础知识」PHP中的注释
建设创客教育运动中的完整体系
What is the difference between foreach and map methods in JS
Department management of cloud e-office projects
What are Dom and BOM in JS
In the future, face brushing payment can occupy a lot of market share
[CISCN2019 华东南赛区]Web11 1
Choose futures companies with state-owned enterprise background to open accounts
What are the traversal methods of arrays in JS
定点一键查询GUI编程的设计与开发
期货开户要和客户经理详谈政策
AQUANEE将在近期登陆Gate以及BitMart,低位布局的良机
我的大四
Seven enabling schemes of m-dao help Dao ecology move towards mode and standardization

![[MRCTF2020]PYWebsite 1](/img/d4/2d9cd06abd7188add668cde77d3075.png)
![[MRCTF2020]Ezpop 1](/img/c0/41873fe5864490ade403eeddc26976.png)



![[网鼎杯 2020 朱雀组]Nmap 1两种解法](/img/fa/b1349cb42b5768b7510217239ba73a.png)
