Home > Database > Mysql Tutorial > body text

It's all here! ! The principles and precautions of MySQL master-slave replication

coldplay.xixi
Release: 2020-11-16 16:55:30
forward
2383 people have browsed it

mysql tutorialThe column introduces the principles and precautions of master-slave replication

It's all here! ! The principles and precautions of MySQL master-slave replication

##Written in Previously

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

Master-slave replication principle

(1) Master records data changes to the binary log (binary log), which is the file specified by the configuration file log-bin. These records are called Binary log events (binary log events);

(2) Slave reads the binary log events in the Master through the I/O thread and writes it to its relay log (relay log);

(3) Slave redo the events in the relay log, execute the event information in the relay log locally one by one, complete the local storage of data, and thus reflect the changes to its own data (data replay).

Notes

(1) The operating system version and number of bits of the master and slave servers are consistent;

(2) Master and Slave The version of the database must be consistent;

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

(4) The Master turns on the binary log, and the server_id of the Master and Slave must be unique within the local area network;

Configuring master-slave replication steps

Master database

(1) Install the database;

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

(3) Start the database and check which log is currently and what the position number is;

(4) Log in to the database and authorize the data replication user (IP address is Slave IP address, if it is a two-way master-slave, you also need to authorize the IP address of the machine. At this time, your IP address is the slave IP address);

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

(6) Transfer backup data to Slave;

(7) Start the database;

The above steps are successful for one-way master-slave setup. If you want to build Steps required for two-way master-slave:

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

(2) Turn on Synchronize and check the status;

Configuration on Slave

(1) Install the database;

(2) Modify the database configuration file and specify the server_id (if you are building a two-way master-slave If so, also enable the binary log log-bin);

(3) Start the database and restore the backup;

(4) Check which log is currently and what is the position number (one-way primary This step is not required from now on, bidirectional master-slave is required);

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

(6) Turn on synchronization and check the status.

Okay, that’s it for today. In the follow-up, we will actually implement MySQL master-slave replication in various ways. I am Binghe. See you in the next issue! !

More related free learning recommendations: mysql tutorial(Video)

The above is the detailed content of It's all here! ! The principles and precautions of MySQL master-slave replication. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.im
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template