当前位置:网站首页>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
边栏推荐
- Zhinai buys melons (DP backpack)
- The slow loading of the first entry page of vite local operation
- 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
- What is the difference between for... In... And for... Of
- I.MX6UL核心模块使用连载-USB接口测试 (六)
- AttributeError: ‘Document‘ object has no attribute ‘pageCount‘
- BGP knowledge points summary
- Redis cluster construction (based on 6.x)
- Niuke - bm39 serialized binary tree [hard]
- [C language brush leetcode] 1604. Warn people who use the same employee card more than or equal to three times within an hour (m)
猜你喜欢

I.MX6UL核心模块使用连载-eMMC读写测试 (四)

【独立站建设】shopify卖家:学会这几点,网上商店销量翻倍!

Characteristics and determination of neuraminidase from Clostridium perfringens in Worthington

Worthington产气荚膜梭菌神经氨酸酶的特征及测定

A pluggable am335x industrial control module onboard WiFi module

Are you still using ==0 null equal to judge null values? How much do you know about isempty and isblank

BGP知识点总结

i.MX6ULL SNVS电源域GPIO状态保持验证

1. Mx6ul core module serial WiFi test (VIII)

I.MX6UL核心模块使用连载-TF卡读写测试 (五)
随机推荐
1. Mx6ul core module serial use - touch screen calibration (IX)
I.MX6UL核心模块使用连载-触摸屏校准 (九)
D - Dire Wolf (interval DP)
Video game quiz? I think it's useless. It's better to do these well!
Leetcode algorithm 147. insert and sort the linked list
1. Mx6ul core module serial WiFi test (VIII)
Jupiter notebook reported an error: notebook validation failed: non unique cell ID '2a4xx6' detected
Ti AM335X工控模块使用beaglebone(bbb)的Debian系统
How to install opengauss manually (non om mode)
Implementation of Ti am335x industrial control module network and file system nfs
Alibaba cloud redis development specification
E2. escape the maze (hard version)
How to use the pagoda panel to deploy the full stack project of node to the server
Make and makefile summary I
阿里云Redis开发规范
i. Mx6ull snvs power domain GPIO status hold verification
ggplot2学习总结
DialogRPT-Dialog Ranking Pretrained Transformers
What is the difference between for... In... And for... Of
[C language brush leetcode] 443. Compressed string (m)