当前位置:网站首页>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 between IsNaN and number.isnan in JS
- 「PHP基础知识」PHP中的注释
- 刷脸支付永远不会过时只会不断的变革
- Seven enabling schemes of m-dao help Dao ecology move towards mode and standardization
- 「PHP基础知识」字符串型(string)的使用
- 软件测试常见面试题
- Rating and inquiry details of futures companies
- Minimum handling charges and margins for futures companies
- [网鼎杯 2020 青龙组]AreUSerialz(BUUCTF)
猜你喜欢
随机推荐
In the future, face brushing payment can occupy a lot of market share
期货公司最低标准的手续费和保证金
定点一键查询GUI编程的设计与开发
Move protocol launched a beta version, and you can "0" participate in p2e
MySQL二级索引中的主键——MySQL存在大量相同数据分页查询优化
How to judge whether a property belongs to an instance object or inherits from a constructor in JS
[MRCTF2020]Ezpop 1
Graph-node部署及测试
你连简单的功能测试都做不好,你拿什么来跟我谈涨薪?
难道Redis真的变慢了吗?
How to use for..Of to traverse objects in JS
How can I get the lowest handling charge for opening a futures account?
期货公司开户的具体事项
期货开户公司交返怎么申请?
解决MySQL JDBC数据批量插入慢的问题
个人收款码不得用于经营收款
Usage and differences among let, const and VaR
[NPUCTF2020]ReadlezPHP 1
Edit delete user
Rating and inquiry details of futures companies








