Detailed explanation of MySQL delayed replication library method

Detailed explanation of MySQL delayed replication library method

Simply put, delayed replication is to set a fixed delay time, such as 1 hour, so that the slave database lags behind the master database by one hour.

MySQL delayed replication library function

Existence is reasonable, and delayed replication can be used to solve the following three types of problems:

1. Used to quickly restore data after database misoperation.

For example, if someone operates a table by mistake, the data in the slave database will not change during the delay period, so the data in the slave database can be used for quick recovery.

Stop the service, import the table from the slave database directly into the master database, and fill in the binlog. Binglog cannot restore the table.

2. Used for delay testing

For example, if you have done a good job of database read-write separation and use the slave database as the read database, then you want to know what will happen when the data is delayed. Then you can use this feature to simulate latency as well.

When the pressure is not too great, the delay will be very small. What is it like when the delay is larger? What does a 5 minute master-slave delay look like?

3. Used for querying old data and other needs

For example, if you often need to check the value of a table or field from a certain day ago, you may need to restore the backup and check it.

If there is a delay from the database, such as a delay of one week, then similar requirements can be solved. Of course, not all teams have this need.

Setting delayed replication

Delayed replication configuration is achieved by setting the MASTER TO MASTER_DELAY parameter on the Slave:

CHANGE MASTER TO MASTER_DELAY = N;

N is a number of seconds. This statement sets the slave database to delay N seconds before synchronizing data with the master database.

Specific operations:

Log in to the Slave database server

mysql>stop slave;
mysql>CHANGE MASTER TO MASTER_DELAY = 600;
mysql>start slave;
mysql>show slave status \G;

Check that the value of SQL_Delay is 600, indicating that the setting is successful.

Command Notes:

SQL_Delay: A non-negative integer representing the number of seconds that the slave lags behind the master.

SQL_Remaining_Delay: When Slave_SQL_Running_State waits until MASTER_DELAY seconds have passed, the Master executes the event.

This field contains an integer indicating how many seconds the delay is in. At other times, this field is 0.

Well, that’s it for today. Some small bits of knowledge are short and beautiful, while long articles are very useful. However, we actually learn very little. Let’s accumulate this little knowledge. For more information about MySQL delayed replication library methods, please see the following related links

You may also be interested in:
  • MySQL master-slave synchronization, read-write separation configuration steps
  • Two solutions to MySQL master-slave database asynchrony
  • The principle and configuration method of MySQL master-slave replication (more detailed)
  • Interpretation of MySQL master-slave configuration and its principle analysis (Master-Slave)
  • Mysql master-slave synchronization backup strategy sharing
  • Analysis and solution of MYSQL master-slave asynchrony delay principle
  • Detailed steps to implement MySQL hot backup under Linux system (MySQL master-slave replication)
  • Mysql master-slave replication (master-slave) actual operation case
  • Detailed explanation of MySQL master-slave replication steps and solutions to common errors
  • An example of solving MySQL master-slave synchronous replication error
  • The implementation principle of Mysql master-slave synchronization
  • Introduction to the heartbeat function of MySQL master-slave replication configuration
  • Configuration example of specifying master-slave synchronization of MySQL database server under Linux
  • Solution to the problem of MySQL master-slave database being out of sync
  • Master-slave synchronization backup steps of MySQL database under Windows environment (one-way synchronization)
  • MYSQL master-slave database synchronization backup configuration method
  • Sharing of the master-slave configuration method of MySQL database
  • Detailed explanation of reducing MySQL master-slave data synchronization delay

<<:  VMware's detailed tutorial on how to create a Linux virtual machine and set up a virtual machine network

>>:  VMware vSphere6.0 server virtualization deployment and installation diagram (detailed steps)

Recommend

How to handle super large form examples with Vue+ElementUI

Recently, due to business adjustments in the comp...

JavaScript canvas to achieve raindrop effect

This article example shares the specific code for...

Centering the Form in HTML

I once encountered an assignment where I was give...

How to display web pages properly in various resolutions and browsers

The key codes are as follows: Copy code The code i...

HTML hyperlink a tag_Powernode Java Academy

Anyone who has studied or used HTML should be fam...

MySQL database migration quickly exports and imports large amounts of data

Database migration is a problem we often encounte...

Front-end advanced teaching you to use javascript storage function

Table of contents Preface Background Implementati...

Meta viewport makes the web page full screen display control on iPhone

In desperation, I suddenly thought, how is the Sin...

How to optimize images to improve website performance

Table of contents Overview What is Image Compress...

How to install PHP7.4 and Nginx on Centos

Prepare 1. Download the required installation pac...

Practice of using Tinymce rich text to customize toolbar buttons in Vue

Table of contents Install tinymce, tinymce ts, ti...

Detailed explanation of script debugging mechanism in bash

Run the script in debug mode You can run the enti...

MySQL 8.0.15 installation and configuration tutorial under Win10

What I have been learning recently involves knowl...