当前位置:网站首页>Master-slave replication in MySQL
Master-slave replication in MySQL
2022-07-26 02:06:00 【Xiaotiantian 666】
Master slave replication refers to the transfer of the master database DDL and DML The operation is passed to the database server through binary log , Then re execute the logs on the slave database ( It's also called redoing ), In this way, the data of the slave database and the master database can be synchronized .
MySQL One master database can be copied to multiple slave databases at the same time , The slave library can also be used as the master library of other slave servers , Achieve Chain replication .
MySQL The copied points mainly include the following three aspects :
1、 There's something wrong with the main database , You can quickly switch to providing services from the library .
2、 Read and write separation , Reduce the access pressure of the main library .
3、 You can perform a backup from the library , To avoid affecting the main library service during backup .
Master slave replication principle :
1、 When the main database commits the transaction , The data changes will be recorded in the binary log file Binlog in .
2、 Read the binary log file of the main library from the library Binlog, Write to the continuation log of the slave Library Relay Log.
3、 Resume the events in the log from the library redo , Will change the data that reflects itself .
build
- Get ready
When you have two servers ready , Install... In the above two servers respectively MySQL, And complete the basic initialization preparation .
# Develop specified 3306 Port number
firewall-cmd --zone=public --add-port=3306/tcp -permanent
firewall-cmd -reload
- Main library configuration
1、 Modify the configuration file /etc/my.cnf
#mysql service ID, Ensure that the entire cluster environment is unique , Value range :1-2^32-1, The default is 1
server-id=1
# Is it read-only ,1 Read only ,0 For reading and writing
read-only=0
# Ignored data , A database that does not need to be synchronized
#binlog-ignore-db=mysql
# Specify a synchronized database
#binlog-do-db=db_name
2、 restart MySQL The server
systemctl restart mysqld
3、 Sign in mysql, Create a remote connection account , And grant master-slave replication permission
# establish itcast user , And set the password , The user can connect to the server from any host MySQL service
create user 'itcast'@'%' identified with mysql_native_password by 'password';
# by 'itcast'@'%' The user assigns master-slave copy permission
grant replication slave on *.* to 'itcast'@'%';
4、 Passing instructions , View binary log coordinates
show master status;
Field meaning description :
file: From which log file to start pushing log files
position: Where to start pushing logs
binlog_ignore_db: Specify a database that does not need to be synchronized
- Configuration from library
1、 Modify the configuration file /et/my.cnf
#mysql service ID, Ensure that the entire cluster environment is unique , Value range :1~2^32-1, It is different from the main library
server-id=2
# Is it read-only ,1 Read only ,0 For reading and writing
read-only=1
2、 Restart MySQL service
systemctl restart mysqld
3、 Sign in mysql, Set master library configuration change replication source to source_host='xxx.xxx',source_user='xxx',source_password='xxx',source_log_file='xxx',source_log_pos='xxx';
The above is 8.0.23 Chinese grammar . If mysql yes 8.0.23 Previous version , The implementation is as follows SQL:change master to master_host='xxx.xxx.xxx.xxx',master_user='xxx',master_password='xxx',master_log_file='xxx',master_log_pos=xxx;
4、 Turn on synchronous operation
start replica; #8.0.22 after
start slave; #8.0.22 Before
5、 Check the master-slave synchronization status
show replica status; #8.0.22 after
show slave status; #8.0.22 Before
边栏推荐
- Jupiter notebook reported an error: notebook validation failed: non unique cell ID '2a4xx6' detected
- (CVPR 2019) GSPN: Generative Shape Proposal Network for 3D Instance Segmentation in Point Cloud
- Pt onnx ncnn conversion problem record (followed by yolov5 training)
- 一款可插拔的AM335X工控模块板载wifi模块
- Kaggle registration method to solve the problem of man-machine verification
- 1. Mx6ul core module use serial -rs485 test (x)
- 【PyQt5打包为exe】
- Infinite fraction path (BFS pruning)
- How to install opengauss manually (non om mode)
- Sqlyog data import and export graphic tutorial
猜你喜欢

Advantages of composition API

How to choose cloud note tool? What can I do with cloud notes?

There is no setter method in grpc list under flutter. How to use related attributes

1. Mx6ul core module use serial RTC test (XII)

SQL手工盲注、报错注入

【2020】【论文笔记】磁控溅射法生长Bi2Te3/CoFeB双层异质结——

Worthington核酸酶、微球菌相关研究及测定方案

Niuke net question brushing training (I)

TI AM335x工控模块网络跟文件系统NFS的实现

Implementation of C iterator
随机推荐
Mark and lightbulbs (thinking)
1. Mx6ul core module serial Ethernet test (VII)
MPLS知识点
Implementation of C iterator
I.MX6UL核心模块使用连载-WIFI测试 (八)
Worthington产气荚膜梭菌神经氨酸酶的特征及测定
Navica工具把远程MySQL导入到本地MySQL数据库
How does Flink SQL configure to print the insert parameter log
# Dest0g3 520迎新赛(更新中)
本地仓库导致的报错
Phoenix中常用shell操作
P3166 number triangle (tolerance and exclusion +gcd)
Guys, the flinksql datahub source table has a field timestamp 16 bits, which is written to ora
LeetCode302场周赛第三题--裁剪数字后查询第 K 小的数字
These practical security browser plug-ins improve your efficiency
CD from grabbing the track to building a streaming media server -- a case study of "moon in the hometown of sleep"
Add an interceptor to resttemplate to record the request response, and you also need to solve the problem that the flow is read only once
Pt onnx ncnn conversion problem record (followed by yolov5 training)
Detailed explanation of redis6.x configuration parameters
Ti am335x industrial control module uses the Debian system of beaglebone (BBB)