Home Database Mysql Tutorial Introduction to the process of how to implement dual-master synchronization of partial tables in MySQL5.7

Introduction to the process of how to implement dual-master synchronization of partial tables in MySQL5.7

Sep 05, 2017 pm 01:31 PM
sub-table Synchronize

This article mainly introduces to you the relevant information about the implementation of some tables of dual-master synchronization in MySQL 5.7. The article introduces it in detail through the example code. It has certain reference learning value for everyone to learn or use mysql. Friends who need it Let’s learn with the editor below.

Preface

Recently encountered a demand. Due to the company's own business, some tables between the two databases need real-time bidirectional data synchronization. And the downtime of any one of the databases will not affect the other database. Record your own technical research here for later use in reconstruction. Not much to say below, let’s take a look at the detailed introduction.

Install MySQL5.7

It is recommended to go directly to the official website and download the yum source to install, after all, it is safe and easy to install.


1

2

3

4

5

6

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

# 安装MySQL5.7

systemctl start mysqld

# 启动MySQL

Copy after login

Configuring dual master

my.cnf configuration

This is just a simple dual master The configuration has not been optimized in database-related aspects. If optimization is needed, you can chat privately.

The configuration of MySQL1 is as follows


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

[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

#设置简单密码

validate_password_policy=0

validate_password_length=1

###主配置

log_bin=bin_log

server-id=1

binlog-do-db=ziyun

# 允许从复制的哪一个库

slave_parallel_type='logical_clock'

#设置复制类型为 LOGICAL_CLOCK

slave_parallel_workers=4

#设置并行数量为 4

###从配置

relay-log=relay-bin

relay-log-index=relay-bin.index

replicate-do-db=ziyun

# 允许复制主服务的库

replicate-do-table=ziyun.test1

# 允许复制主服务的库的哪一张表

replicate-do-table=ziyun.test2

Copy after login

The configuration of MySQL2 is basically the same as above, just modify one server-id=2, keep the others unchanged

MySQL command configuration

The following are all configured in the SQL command line interface

Main configuration:


1

2

3

4

5

6

7

8

9

10

mysql> CREATE USER 'slave'@'192.168.1.100' IDENTIFIED BY '123.com';

mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave'@'192.168.1.100';

# 授权复制的用户和密码

mysql> 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)

Copy after login

From configuration:


1

2

3

4

5

6

7

8

9

10

11

12

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

# 确定以上都为yes,并且无任何报错即可

Copy after login

The same configuration can be done on MySQL2

Dual master Synchronous test


#Here I have previously built a ziyun database on both sides, and built the test1 test2 test3 table. The test results are as follows:

Summarize

The above is the detailed content of Introduction to the process of how to implement dual-master synchronization of partial tables in MySQL5.7. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solve the problem of playing headphones and speakers at the same time in win11 Solve the problem of playing headphones and speakers at the same time in win11 Jan 06, 2024 am 08:50 AM

Generally speaking, we only need to use one of the headphones or speakers at the same time. However, some friends have reported that in the win11 system, they encountered the problem of headphones and speakers sounding at the same time. In fact, we can turn it off in the realtek panel and it will be fine. , let’s take a look below. What should I do if my headphones and speakers sound together in win11? 1. First find and open the "Control Panel" on the desktop. 2. Enter the control panel, find and open "Hardware and Sound" 3. Then find the "Realtek High Definition" with a speaker icon. Audio Manager" 4. Select "Speakers" and click "Rear Panel" to enter the speaker settings. 5. After opening, we can see the device type. If you want to turn off the headphones, uncheck "Headphones".

One or more items in the folder you synced do not match Outlook error One or more items in the folder you synced do not match Outlook error Mar 18, 2024 am 09:46 AM

When you find that one or more items in your sync folder do not match the error message in Outlook, it may be because you updated or canceled meeting items. In this case, you will see an error message saying that your local version of the data conflicts with the remote copy. This situation usually happens in Outlook desktop application. One or more items in the folder you synced do not match. To resolve the conflict, open the projects and try the operation again. Fix One or more items in synced folders do not match Outlook error In Outlook desktop version, you may encounter issues when local calendar items conflict with the server copy. Fortunately, though, there are some simple ways to help

MySql data migration and synchronization: How to achieve MySQL data migration and synchronization between multiple servers MySql data migration and synchronization: How to achieve MySQL data migration and synchronization between multiple servers Jun 15, 2023 pm 07:48 PM

MySQL is a very popular open source relational database management system that is widely used in various web applications, enterprise systems, etc. In modern business application scenarios, most MySQL databases need to be deployed on multiple servers to provide higher availability and performance, which requires MySQL data migration and synchronization. This article will introduce how to implement MySQL data migration and synchronization between multiple servers. 1. MySQL data migration MySQL data migration refers to the data migration in the MySQL server.

Teach you how to synchronize the win10 clipboard with your mobile phone Teach you how to synchronize the win10 clipboard with your mobile phone Jan 06, 2024 am 09:18 AM

A very useful function of win10 clipboard is the cross-device cloud storage function, which is very useful and can help users copy and paste simultaneously on PC devices and mobile devices. The setting method is very simple, just set it on the clipboard in the system. Synchronize win10 clipboard to mobile phone 1. First click Start in the lower left corner to enter settings. 2. Then click "System". 3. Select "Clipboard" on the left. 4. Finally, click Login in "Cross-device synchronization" on the right, and then select your mobile phone.

How to select specific folders to sync in OneDrive in Windows 11 How to select specific folders to sync in OneDrive in Windows 11 Apr 13, 2023 pm 04:22 PM

The OneDrive app on your system stores all your files and folders in the cloud. But sometimes users don't want certain files or folders to be stored and take up OneDrive space that is limited to 5 GB without a subscription. To do this, there is a setting in the OneDrive app that allows users to select files or folders to sync on the cloud. If you are also looking for this, then this article will help you select folders or files to sync in OneDrive on Windows 11. How to select certain folders to sync in OneDrive in Windows 11 Note: Make sure the OneDrive app is connected and synced

How to synchronize Baidu cloud synchronization disk How to synchronize Baidu cloud synchronization disk Feb 23, 2024 pm 01:22 PM

How to synchronize Baidu Cloud Sync Disk? You can select files to synchronize in Baidu Cloud Sync Disk, but most users don’t know how to synchronize Baidu Cloud files. Next is the graphic tutorial of Baidu Cloud Sync Disk synchronization method brought by the editor for users. Interested users come and take a look! How to synchronize Baidu Cloud Sync Disk 1. First enter the computer desktop, right-click the [Baidu Cloud Sync Disk] icon and select [Settings]; 2. Then expand the service window, switch to the [Advanced Settings] page and click [Select Folder]; 3. Finally switch to the page as shown below, check the files that need to be synchronized and click [OK].

Locks and synchronization in Python concurrent programming: keeping your code safe and reliable Locks and synchronization in Python concurrent programming: keeping your code safe and reliable Feb 19, 2024 pm 02:30 PM

Locks and Synchronization in Concurrent Programming In concurrent programming, multiple processes or threads run simultaneously, which can lead to resource contention and inconsistency issues. To solve these problems, locks and synchronization mechanisms are needed to coordinate access to shared resources. Concept of Lock A lock is a mechanism that allows only one thread or process to access a shared resource at a time. When one thread or process acquires a lock, other threads or processes are blocked from accessing the resource until the lock is released. Types of locks There are several types of locks in python: Mutex lock (Mutex): ensures that only one thread or process can access resources at a time. Condition variable: Allows a thread or process to wait for a certain condition and then acquire the lock. Read-write lock: allows multiple threads to read resources at the same time, but only allows one thread to write resources

The key concept of C++ multi-threaded programming is how to synchronize threads? The key concept of C++ multi-threaded programming is how to synchronize threads? Jun 03, 2024 am 11:55 AM

Key concepts of C++ multi-thread synchronization: Mutex lock: ensure that the critical section can only be accessed by one thread. Condition variables: Threads can be awakened when specific conditions are met. Atomic operation: A single uninterruptible CPU instruction ensures the atomicity of shared variable modifications.

See all articles