Detailed explanation of mysql filtering replication ideas

Detailed explanation of mysql filtering replication ideas

mysql filtered replication

Two ideas:

  • Implemented on the binlog of the main library (not recommended, try to ensure that the binlog of the main library is complete)
  • Implemented from the library's sql thread

Therefore, try not to use master-slave filtering replication, and only use it on the slave database, because the integrity of the binlog should be guaranteed as much as possible.

Implemented on the main database

To ensure the integrity of the binary log on the Master side, binary log filtering is not used.

Main library configuration parameters:

#Add binlog-do-db=db_name in the configuration file #Define a whitelist and only record operations related to the specified database in the binary log. If the main database crashes, only the contents of the specified database will be restored. This is not recommended on the main server, as it will result in incomplete logs.
binlog-ignore-db=db_name #Define a blacklist. Write operations on the database defined as ignore will not be recorded in the binary log.

Implemented from the library

You can download the configuration file

REPLICATE_DO_DB = (db_list) #Filter which libraries to copyREPLICATE_IGNORE_DB = (db_list) #Which libraries not to copyREPLICATE_DO_TABLE = (tbl_list) #Filter tableREPLICATE_IGNORE_TABLE = (tbl_list) #Ignore filtered tableREPLICATE_WILD_DO_TABLE = (wild_tbl_list) #Filter table according to regular matchREPLICATE_WILD_IGNORE_TABLE = (wild_tbl_list) #Ignore filtering these tables according to regular matchREPLICATE_REWRITE_DB = (db_pair_list)
#Rewrite the statements in db1 of the source database to db2 of the slave database
CHANGE REPLICATION FILTER REPLICATE_REWRITE_DB = ((db1, db2));

grammar:

Official website syntax reference: https://dev.mysql.com/doc/refman/5.7/en/change-replication-filter.html

CHANGE REPLICATION FILTER filter[, filter][, ...]

filter: {
    REPLICATE_DO_DB = (db_list)
  | REPLICATE_IGNORE_DB = (db_list)
  | REPLICATE_DO_TABLE = (tbl_list)
  | REPLICATE_IGNORE_TABLE = (tbl_list)
  | REPLICATE_WILD_DO_TABLE = (wild_tbl_list)
  | REPLICATE_WILD_IGNORE_TABLE = (wild_tbl_list)
  | REPLICATE_REWRITE_DB = (db_pair_list)
}
# Implement filtered replication from the library stop slave sql_thread;
​ change replication filter replicate_do_db=(db);
​ start slave sql_thread;

#Cancel filtered replication stop slave sql_thread;
​ change replication filter replicate_do_db=();
​ start slave sql_thread;

Some questions

The master database deletes a table, but the slave database does not have this table, causing the slave database sql thread to close.

Or the master and slave are normal, but the slave accidentally deletes a table, and the master deletes the table later. The slave will then delete the non-existent table, report an error, and cause the SQL thread to exit.

Solution: Skip this step

Solution: Skip the erroneous operation step of the slave sql thread stop slave sql_thread;

#Find Executed_Gtid_Set and execute to 19
set gtid_next='94fc1fbe-b7a0-11eb-b0a0-000c2969aba1:20'; assign gtid to the next transaction begin; commit;
set gtid_next=automatic; the system automatically assigns gtid
start slave sql_thread;

This is the end of this article about the detailed explanation of MySQL filtering and replication ideas. For more relevant MySQL filtering and replication content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How does MySQL achieve multi-version concurrency?
  • MySQL foreign key (FOREIGN KEY) usage case detailed explanation
  • How to use stored procedures in MySQL to quickly generate 1 million records
  • Python interface automation briefly analyzes the pymysql database operation process
  • MySQL transaction control flow and ACID characteristics
  • Mysql uses stored procedures to quickly add millions of data sample code
  • Implementation of removing overlapping time and calculating time difference in MySQL
  • In MySQL database, datetime, bigint, and timestamp are used to represent time selection. Which one is the most efficient for storing time?
  • Specific use of MySQL global locks and table-level locks
  • Analysis of MySQL crash recovery based on Redo Log and Undo Log

<<:  What are the image file formats and how to choose

>>:  Solve the problem of managing containers with Docker Compose

Recommend

Button is stretched on both sides in IE

When you write buttons (input, button), you will f...

Writing and understanding of arrow functions and this in JS

Table of contents Preface 1. How to write functio...

Implementation code of html floating prompt box function

General form prompts always occupy the form space...

Detailed tutorial on installing MySQL 8.0 from source code on CentOS 7.4

Table of contents 1. Environment 2. Preparation 3...

mysql 5.7.5 m15 winx64.zip installation tutorial

How to install and configure mysql-5.7.5-m15-winx...

MySQL 8.0.15 installation and configuration graphic tutorial under Win10

This article records the installation and configu...

Native js to realize bouncing ball

On a whim, I wrote a case study of a small ball b...

JavaScript implements the generation of 4-digit random verification code

This article example shares the specific code for...

CentOS 7.9 installation and configuration process of zabbix5.0.14

Table of contents 1. Basic environment configurat...

MySQL advanced learning index advantages and disadvantages and rules of use

1. Advantages and Disadvantages of Indexes Advant...

VMware, nmap, burpsuite installation tutorial

Table of contents VMware BurpSuite 1. Virtual mac...

How to deploy code-server using docker

Pull the image # docker pull codercom/code-server...

How to implement property hijacking with JavaScript defineProperty

Table of contents Preface Descriptors Detailed ex...

Install mysql5.7.17 using RPM under Linux

The installation method of MySQL5.7 rpm under Lin...