当前位置:网站首页>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 
边栏推荐
- Differences among apply, call, and bind in JS
- 期货开户要和客户经理详谈政策
- 建设创客教育运动中的完整体系
- PHP 实现与MySQL的数据交互
- 存储过程试炼2--建立Test表测试不同类型的存储过程
- What are alpha and beta tests?
- 解析新时代所需要的创客教育DNA
- The LAF protocol elephant of defi 2.0 may be one of the few profit-making means in your bear market
- Permission display - dynamic list on the left
- NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
猜你喜欢
![[MRCTF2020]PYWebsite 1](/img/d4/2d9cd06abd7188add668cde77d3075.png)
[MRCTF2020]PYWebsite 1

Several ways of element positioning in page layout

How can I get the lowest handling charge for opening a futures account?

The LAF protocol elephant of defi 2.0 may be one of the few profit-making means in your bear market

Seven enabling schemes of m-dao help Dao ecology move towards mode and standardization

Build a complete system in the maker education movement

Choose futures companies with state-owned enterprise background to open accounts

Amazon evaluation autotrophic number, how to carry out systematic learning?

SeekTiger即将上线STI聚变Mining功能,获取OKA通证

机器人编程与交叉学科的融合延伸
随机推荐
Choose a qualified futures company to open an account
Analyze the maker education DNA needed in the new era
期货开户怎么选择好的期货公司 ?
软件测试常见面试题
[MRCTF2020]PYWebsite 1
XXE&XML 漏洞
Build a complete system in the maker education movement
Sealem Finance-基于Web3的全新去中心化金融平台
Docker部署redis单机版本 - 修改redis密码和持久化方式
The business logic of face brushing changed significantly, and merchants vied for war smoke to rise again
期货公司最低标准的手续费和保证金
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Basic layout of the page
Common interview questions in software testing
[CISCN2019 华东南赛区]Web11 1
市场冷空气来袭,SeekTiger如何逆流而上?
刷脸商业逻辑重大改变商户争抢烽烟再起
万字解析MySQL索引原理——InnoDB索引结构与读取
dbswitch数据迁移数据增量时如何不覆盖目标源数据
The LAF protocol elephant of defi 2.0 may be one of the few profit-making means in your bear market