当前位置:网站首页>MySQL: MySQL Cluster - Principle and Configuration of Master-Slave Replication
MySQL: MySQL Cluster - Principle and Configuration of Master-Slave Replication
2022-08-10 22:41:00 【_Sauron】
Foreword
In the actual production environment, if the reading and writing of the mysql database are operated in one database server, it cannot meet the actual needs in terms of security, high availability, or high concurrency.
strong>Generally, data should be synchronized through master-slave replication, and then the concurrent load capacity of the database should be improved through read-write separation.
1. Data Backup - Hot Backup & Disaster Recovery & High Availability
2. Separation of Read and Write to Support Greater Concurrency
Article table of contents
Introduction to Principles

The process of master-slave replication: two logs (binlog binary log & relay log log) and three threads (one thread of master and two threads of
slave)
1. The update operation of the main library is written into the binlog binary log.
2. The master server creates a binlog dump thread to send the binary log content to the slave server.
3. When the slave machine executes the START SLAVE command, an IO thread will be created on the slave server, and the binary log of the master will be copied to its relay log.
First the slave starts a worker thread (I/O thread), the I/O thread opens a normal connection on the master, and then starts the
binlog dump process, which reads events from the master's binary log, if it has caught up with the
master, it sleeps and waits for the master to generate new events, which the I/O thread writes to the relay log.
4. The sql slave thread (sql slave thread) processes the last step of the process, the sql thread reads events from the relay log, and replays the events in
to update the data of the slave machine so that it matches the masterdata are consistent.As long as the thread is consistent with the I/O thread, the relay log will usually be in the OS cache, so the overhead of the relay log is small.
Question
Why not use the I/O thread to directly read data from the bin-log of the main library and write it to the slave library, but write to the relay log?
Because there may be a lot of bin-log content in the main library, and an I/O thread reads slowly, the data updated from the slave library may be more and more different from the content of the main library, and the data lags behind.
Configuration
Master (centos7): 192.168.131.129
Slave (win10): 192.168.0.6
Ensure network connectivity between master and slave, and ensure that port 3306 is open.
Master configuration:
1. Open binary log, directory: /etc/my.cnf
Configure log_bin and globally unique server-id.

2. Create an account for master-slave library communication
mysql> CREATE USER 'mslave'@'192.168.131.1' IDENTIFIED BY '[email protected]';
mysql> GRANT REPLICATION SLAVE ON . to 'mslave'@'192.168.131.1' IDENTIFIED BY '[email protected]';
mysql> FLUSH PRIVILEGES;
3. Get the log file name and position of binlog
mysql> show master status;
slave configuration:
1. Configure a globally unique server-id (involving modifying the configuration file, you need to restart the mysql57 service) 


2. Use the account created by the master to read the binlog synchronization data (stop slave; start slave)
Adjust the parameters according to your own situation
Example, configure the personal main library bin-log wherever it is located
3. START SLAVE
View the master-slave replication status through the show slave status command.show processlist to view the running status of master and slave related threads
.

Common mistakes
- IO_ERROR

Solution:
- Use the ping command to check whether the network is connected?
- Is the port 3306 of the machine where the main library is located normal?telnet xxx.xxx.xxx.xxx 3306
- Does the firewall restrict ports?
- View the error log of the main library /var/log/mysql/mysqld.log
2.Last_Error
Solution: Check if the configuration information is wrong, then restart the slave thread

3.SQL_Error

Error reason:
The slave library has not synchronized the mytest library, but the master library uses the SQL of drop database mytest, then this SQL will be written to the bin-log log, and then the I/O thread will read this SQL and write it to the relay log, the slave library reads this SQL from the relay log, and the error is generated after execution.
Solution:
You can stop the slave thread, skip an error, and restart the slave
stop slave;
set global sql_slave_skip_counter = 1;
start slave;
边栏推荐
- GMT,UTC,CST,DST,RTC,NTP,SNTP,NITZ: 嵌入式的时间
- 计算需要的MIPI lane数目
- "DevOps Night Talk" - Pilot - Introduction to CNCF Open Source DevOps Project DevStream - feat. PMC member Hu Tao
- Shell programming specification and variables
- What is Jmeter? What are the principle steps used by Jmeter?
- IM 即时通讯开发如何设计图片文件的服务端存储架构
- [Maui official version] Create a cross-platform Maui program, as well as the implementation and demonstration of dependency injection and MVVM two-way binding
- Service - DNS forward and reverse domain name resolution service
- 【Maui正式版】创建可跨平台的Maui程序,以及有关依赖注入、MVVM双向绑定的实现和演示
- shell programming without interaction
猜你喜欢

Translating scientific and technological papers, how to translate from Russian to Chinese

IM 即时通讯开发如何设计图片文件的服务端存储架构

H3C S5130 IRF做堆叠

win系统下pytorch深度学习环境安装

学会开会|成为有连接感组织的重要技能

阿里云新增三大高性能计算解决方案,助力生命科学行业快速发展

What are the concepts, purposes, processes, and testing methods of interface testing?

新一代网络安全防护体系的五个关键特征

How many threads does LabVIEW allocate?

Redis Performance Impact - Asynchronous Mechanisms and Response Latency
随机推荐
过滤器
商家招募电商主播要考虑哪些内容
链表相加(二)
C # Hex file transfer skills necessary article 】 【 bin file code implementation
"DevOps Night Talk" - Pilot - Introduction to CNCF Open Source DevOps Project DevStream - feat. PMC member Hu Tao
元宇宙社交应用,靠什么吸引用户「为爱发电」?
链表中的节点每k个一组翻转
OneNote 教程,如何在 OneNote 中整理笔记本?
shell (text printing tool awk)
交换机和生成树知识点
Black cat takes you to learn Makefile Part 11: When the header file a.h changes, how to recompile all the .c files that depend on the header file a.h
使用 Cloudreve 搭建私有云盘
Qualcomm Platform Development Series Explanation (Application) Introduction to QCMAP Application Framework
camera预览流程 --- 从HAL到OEM
Merge k sorted linked lists
shell编程之免交互
翻译科技论文,俄译中怎样效果好
CIKM2022 | 基于双向Transformers对比学习的序列推荐
STL-stack
c语言之 练习题1 大贤者福尔:魔法数,神奇的等式