Detailed explanation of the implementation process of dual-master synchronization of partial tables in MySQL 5.7

Detailed explanation of the implementation process of dual-master synchronization of partial tables in MySQL 5.7

Preface

Recently, I encountered a requirement. Due to the company's own business, some tables between two databases need to synchronize data in real time and bidirectionally, and the downtime of any one database will not affect the other database. Here I record my own technical research for use in later reconstruction. Without further ado, let’s take a look at the detailed introduction.

Install MySQL 5.7

It is recommended to go directly to the official website https://dev.mysql.com to download the yum source for installation, after all, it is safe and convenient.

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum -y install mysql57-community-release-el7-11.noarch.rpm
yum -y install mysql-server
# Install MySQL 5.7
systemctl start mysqld
# Start MySQL

Configuring Dual Active

my.cnf configuration

Here we only do a simple dual-master configuration, and no database-related optimization is done. If you need optimization, you can chat privately.

The configuration of MySQL1 is as follows

[mysqld]
vim /etc/my.cnf
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
skip_name_resolve=ON
#Set simple password validate_password_policy=0
validate_password_length=1
###Main configuration log_bin=bin_log
server-id=1
binlog-do-db=ziyun
# Which library is allowed to be replicated from slave_parallel_type='logical_clock'
#Set the replication type to LOGICAL_CLOCK
slave_parallel_workers=4
#Set the number of parallel operations to 4
###From the configuration relay-log=relay-bin
relay-log-index=relay-bin.index
replicate-do-db=ziyun
# Allow replication of the main service library replicate-do-table=ziyun.test1
# Which table of the main service library is allowed to be replicated replicate-do-table=ziyun.test2

The configuration of MySQL2 is basically the same as above, except that server-id=2 is changed and the rest remain unchanged.

MySQL command configuration

The following are configured in the SQL command line interface

Main configuration:

mysql> CREATE USER 'slave'@'192.168.1.100' IDENTIFIED BY '123.com'; 
mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave'@'192.168.1.100';
# Authorized replication user and passwordmysql> show master status;
+-----------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------+----------+--------------+------------------+-------------------+
| bin_log.000002 | 8384 | ziyun | | |
+-----------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

From the configuration:

mysql> CHANGE MASTER TO
 -> MASTER_HOST='192.168.1.101',
 -> MASTER_USER='slave',
 -> MASTER_LOG_FILE='bin_log.000002',
 -> MASTER_LOG_POS=8384;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
# Make sure all the above are yes and there are no errors.

The same configuration can be done on MySQL2

Dual master synchronization test

Here I have built a ziyun database on both sides, and created test1 test2 test3 tables. The test results are as follows:

Summarize

The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • MySQL realizes the synchronization of data between two tables
  • MySql development of automatic synchronization table structure

<<:  VUE implements a Flappy Bird game sample code

>>:  In-depth understanding of umask in new linux file permission settings

Recommend

In-depth analysis of the role of HTML <!--...--> comment tags

When we check the source code of many websites, w...

Detailed explanation of single-row function code of date type in MySQL

Date-type single-row functions in MySQL: CURDATE(...

Basic Implementation of AOP Programming in JavaScript

Introduction to AOP The main function of AOP (Asp...

Solution to the impact of empty paths on page performance

A few days ago, I saw a post shared by Yu Bo on G...

Sample code for making a drop-down menu using pure CSS

Introduction: When I looked at interview question...

Implementation of Nginx filtering access logs of static resource files

Messy log Nginx in daily use is mostly used as bo...

Detailed explanation of basic operation commands for Linux network settings

Table of contents View network configuration View...

Vue custom optional time calendar component

This article example shares the specific code of ...

Summary of MySQL usage specifications

1. InnoDB storage engine must be used It has bett...

Vue3.0 adaptive operation of computers with different resolutions

First we need to install some dependencies npm i ...

Disable IE Image Toolbar

I just tried it on IE6, and it does show the toolb...

Use scripts to package and upload Docker images with one click

The author has been working on a micro-frontend p...

js canvas realizes circular water animation

This article example shares the specific code of ...

Comparing Document Locations

<br />A great blog post by PPK two years ago...