当前位置:网站首页>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 
边栏推荐
- 存储过程试炼1--爱的初相识
- 选择正规的资质好的期货公司开户
- What are alpha and beta tests?
- 攻防世界-mfw
- 亚马逊测评自养号,如何进行系统性的学习?
- NFT new paradigm, okaleido innovation NFT aggregation trading ecosystem
- [MRCTF2020]PYWebsite 1
- The LAF protocol elephant of defi 2.0 may be one of the few profit-making means in your bear market
- Amazon evaluation autotrophic number, how to carry out systematic learning?
- How JS determines whether an object belongs to a class
猜你喜欢

市场冷空气来袭,SeekTiger如何逆流而上?

User page management

How can seektiger go against the cold air in the market?

万字解析MySQL索引原理——InnoDB索引结构与读取

minio8.x版本设置policy桶策略

Prototype and prototype chain in JS

Rating and inquiry details of futures companies

解决MySQL JDBC数据批量插入慢的问题

Mysql5.7版本如何实现主从同步

Permission configuration, component value transfer
随机推荐
Rating and inquiry details of futures companies
jenkins构建镜像自动化部署
期货开户要和客户经理详谈政策
Dimitra and ocean protocol interpret the secrets behind agricultural data
亚马逊测评自养号,如何进行系统性的学习?
MySQL二级索引中的主键——MySQL存在大量相同数据分页查询优化
期货公司最低标准的手续费和保证金
Minio分片上传解除分片大小限制 - chunk size must be greater than 5242880
Construction of layout and display of weather forecast
难道Redis真的变慢了吗?
Sealem Finance - a new decentralized financial platform based on Web3
Aquanee will land in gate and bitmart in the near future, which is a good opportunity for low-level layout
使用Docker部署Redis进行高可用主从复制
CAP原则
Permission configuration, component value transfer
Specific matters of opening accounts of futures companies
给测试小姐姐的第三封信 | ORACLE存储过程知识分享和测试说明
NFT市场格局仍未变化,Okaleido能否掀起新一轮波澜?
The difference between deep copy and shallow copy in JS
Differences between IsNaN and number.isnan in JS