A brief overview of the replication logic: 1. The master database records changes to the database instance in the binlog. The above is the default asynchronous replication logic. Semi-synchronous replication is slightly different and will not be described here. In addition, it is very easy to determine whether there is a delay in the slave library: Causes of delay and solutions 〇Frequent DML requests to the main database (large tps)That is, the main database has many write requests, with a large number of concurrent insert, delete, and update operations, which generates a large amount of binlog in a short period of time. 【Cause Analysis】 The master database writes data concurrently, while the slave database 【Solution】Do sharding and disperse write requests by scaling out. Or consider upgrading to MySQL 5.7+ and enabling parallel replication based on logical clocks. 〇The main database executes large transactions For example, importing a large amount of data, 【Cause Analysis】If the master database takes 200 seconds to update a large table, and the master and slave databases have similar configurations, the slave database will also need to spend almost the same amount of time to update the large table. At this time, slave database delays begin to accumulate, and subsequent events cannot be updated. 【Solution】Split large transactions and submit them in time. 〇The main database executes DDL statements on large tables The phenomenon is similar to that of executing large transactions in the main database. 【Cause Analysis】 1. DDL is not started and is blocked. 【Solution】 Use 〇The configuration of the master library and the slave library is inconsistent: 【Cause Analysis】Hardware: The master instance server uses SSD, while the slave instance server uses ordinary SAS disk, and the CPU main frequency is inconsistent. Configuration: such as inconsistent RAID card write strategy, inconsistent OS kernel parameter settings, inconsistent MySQL disk placement strategy, etc. 【Solution】 Try to unify the configuration of DB machines (including hardware and option parameters) 〇The table lacks a primary key or unique index When 【Cause Analysis】Let's assume an extreme case where the master database updates 200,000 rows of data in a 5 million table. The update statement requires a full table scan. In row format, 200,000 update operations are recorded in the binlog. In this case, SQL Thread replay will be very slow, and each update may require a full table scan. 【Solution】Check the table structure to ensure that each table has an explicit auto-increment primary key and create appropriate indexes. 〇The pressure from the library itself is too great 【Cause Analysis】 The slave database executes a large number of select requests, or most of the select requests of the business are routed to the slave database instance, even a large number of OLAP businesses, or the slave database is being backed up, etc. 【Solution】Create more slaves to distribute read requests and reduce the pressure on existing slave instances. 0MyISAM storage engine At this time, the slave library 【Cause Analysis】 MyISAM only supports table-level locks, and reading and writing cannot be performed concurrently. 【Solution】 Of course, I choose to forgive it. Since I have chosen MyISAM, I should be mentally prepared. (There are other scenarios where MyISAM is not recommended for use in a replication structure.) Summarize: Use If none of the above reasons apply, please ask the DBA experts for help. Of course, The full text is over. The above is the detailed content of the causes and solutions of MySQL master-slave replication delay. For more information about MySQL master-slave replication delay, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Let's talk about Vue's mixin and inheritance in detail
>>: Nginx forwarding based on URL parameters
When you feel that there is a problem with MySQL ...
This article mainly introduces the analysis of th...
1. Download from the official website and unzip h...
This example takes the installation of Python 3.8...
Demand: This demand is an urgent need! In a subwa...
When the amount of data in MySQL is large, limit ...
I believe that students who have learned about th...
Generally speaking, when we view the contents of ...
1. Import the basic style of external CSS files U...
Today I am a little confused about <a href=&quo...
Code example: public class JDBCDemo3 { public sta...
exhibit design Password strength analysis The pas...
Table of contents DOM node Element node: Text nod...
Table of contents Preface 1. Nginx installation 1...
Intersection Selector The intersection selector i...