MySQL master-slave replication principle and points to note

MySQL master-slave replication principle and points to note

Written in front

I have been writing a special topic on Mycat recently. Since many of my friends are going out for interviews recently, they asked me if I could briefly write down the master-slave replication principles and precautions of MySQL, because I was asked these questions in previous interviews. Me: Sure, it’s arranged! !

Master-slave replication principle

(1) The master records data changes in the binary log, which is the file specified by the configuration file log-bin. These records are called binary log events.

(2) The slave reads the binary log events in the master through the I/O thread and writes them to its relay log;

(3) The slave redoes the events in the relay log and executes the event information in the relay log one by one locally to complete the local storage of the data, thereby reflecting the changes to its own data (data replay).

Precautions

(1) The operating system versions and bit numbers of the master and slave servers are consistent;

(2) The versions of the Master and Slave databases must be consistent;

(3) The data in the Master and Slave databases must be consistent;

(4) The master starts binary logging, and the server_id of the master and slave must be unique within the local area network;

Configure master-slave replication steps

Master database

(1) Install the database;

(2) Modify the database configuration file, specify the server_id, and enable binary logging (log-bin);

(3) Start the database and check the current log and position number.

(4) Log in to the database and authorize the data replication user (the IP address is the slave IP address. If it is a two-way master-slave, you also need to authorize the local IP address. In this case, your own IP address is the slave IP address);

(5) Back up the database (remember to lock and unlock it);

(6) Send backup data to Slave;

(7) Start the database;

The above steps are for a successful one-way master-slave setup. To build a two-way master-slave setup, you need to:

(1) Log in to the database and specify the address, user, password and other information of the Master (this step is only required for bidirectional master-slave);

(2) Enable synchronization and check the status;

Configuration on Slave

(1) Install the database;

(2) Modify the database configuration file and specify server_id (if a bidirectional master-slave system is being built, binary log log-bin must also be enabled);

(3) Start the database and restore the backup;

(4) Check which log is currently being viewed and what its position number is (this step is not required for one-way master-slave communication, but is required for two-way master-slave communication);

(5) Specify the Master's address, user, password, and other information;

(6) Enable synchronization and check the status.

Okay, that’s all for today. We will implement MySQL master-slave replication in various ways in the future. I’m Binghe, see you next time! !

The above is the detailed content of the principle of MySQL master-slave replication and the points that need attention. For more information about MySQL master-slave replication, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • How to fix duplicate key issues in MySQL master-slave replication
  • Comprehensive analysis of MySql master-slave replication mechanism
  • Detailed explanation of MySQL master-slave replication and read-write separation
  • MYSQL database GTID realizes master-slave replication (super convenient)
  • Implementation principle and configuration of MySql master-slave replication
  • How to skip errors in mysql master-slave replication
  • MySQL master-slave replication configuration process
  • Comprehensive interpretation of MySQL master-slave replication, from principle to installation and configuration
  • Summary of several replication methods for MySQL master-slave replication
  • Common repair methods for MySQL master-slave replication disconnection

<<:  Vue uses the Element el-upload component to step on the pit

>>:  Detailed explanation of Docker usage under CentOS8

Recommend

Detailed explanation of how Node.js middleware works

Table of contents What is Express middleware? Req...

ie filter collection

IE gave us a headache in the early stages of deve...

How to solve the 10060 unknow error when Navicat remotely connects to MySQL

Preface: Today I want to remotely connect to MySQ...

Alibaba Cloud Server Domain Name Resolution Steps (Tutorial for Beginners)

For novices who have just started to build a webs...

Vue implements form validation function

This article mainly describes how to implement fo...

How to force vertical screen on mobile pages

I recently wrote a mobile page at work, which was...

A complete list of meta tag settings for mobile devices

Preface When I was studying the front end before,...

SQL implementation of LeetCode (196. Delete duplicate mailboxes)

[LeetCode] 196.Delete Duplicate Emails Write a SQ...

A brief discussion on the binary family of JS

Table of contents Overview Blob Blob in Action Bl...

Implementation of FIFO in Linux process communication

FIFO communication (first in first out) FIFO name...

Dynamically edit data in Layui table row

Table of contents Preface Style Function Descript...

Summary of methods for writing judgment statements in MySQL

How to write judgment statements in mysql: Method...