In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What is master-slave replication
Master-slave replication is used to establish a database environment exactly the same as the master database, which is called the slave database. The master database is generally a quasi-real-time business database. Single item and asynchronous assignment are supported in the most commonly used mysql databases. During the assignment process, one server acts as the master server and the other server acts as the slave server; at this point the master server writes the update information to a specific binary file.
An index of the file is maintained to track log loops. This log can be recorded and sent to updates from the server. When a slave server connects to the master server, the slave server informs the master server to read the location of the last successful update from the server's log file. The slave server then receives any updates from which time it occurs, then locks it and waits for the master server to notify the new update.
Second, the role of master-slave replication
First, to ensure the security of the data; do the hot backup of the data, as a backup database, after the failure of the master database server, you can switch to the slave database to continue to work to avoid the loss of data.
The second is to improve the performance of Iwhite O; with the increasing amount of business in daily production, the access frequency of Ihammer O is getting higher and higher, which cannot be satisfied by a single machine, so it is necessary to store multiple databases at this time, which can effectively reduce the frequency of disk Isign O access and improve the performance of a single device.
The third is the separation of read and write, so that the database can support greater concurrency, which is especially important in the report. As part of the report sql statement is very slow, resulting in table lock, affecting the front desk service. If the foreground uses master and the report uses slave, then the report sql will not cause the foreground lock and ensure the speed of the foreground.
Third, the principle of master-slave replication
Files involved in master-slave replication
Main library: binlog
From the library:
Relaylog Relay Log master.info main Library Information File relaylog.info relaylog Application Information
Three threads involved in master-slave replication
Main library:
Binlog_Dump Thread:
From the library:
SLAVE_IO_THREAD
SLAVE_SQL_THREAD
The specific principle is shown in the figure:
1. Execute the change master to command from the database (connection information of the primary database + starting point of replication)
two。 The above information will be recorded to the master.info file from the database.
3. Execute the start slave command from the database and start the SLAVE_IO_THREAD and SLAVE_SQL_THREAD threads immediately
4. From the database SLAVE_SQL_THREAD, read the information in the master.info file to get the location information of the IP,PORT,User,Pass,binlog
5. Request to connect to the master database from the database SLAVE_IO_THREAD. The master database provides a special SLAVE_IO_THREAD that is responsible for interacting with SLAVE_SQL_THREAD.
6.SLAVE_IO_THREAD requests a new binlog of the master database based on the location information of the binlog
7. The master database sends the latest binlog to the SALVE_IO_THREAD of the slave database through the network TP through Binlog_DUMP_Thread.
8.SLAVE_IO_THREAD receives the new binlog log, stores it in the TCP/IP cache, immediately returns ACK to the main library, and updates the master.info
9.SLAVE_IO_THREAD dumps the data in the TCP/IP cache to disk relaylog.
10.SLAVE_SQL_THREAD reads the information in relay.info and obtains the location information of the relaylog that has been applied last time.
11.SLAVE_SQL_THREAD will play back the latest relaylog according to the last location, and update the relay.info information again.
twelve。 From the database will automatically purge the application of relay for regular cleaning
Once the master-slave replication is successfully constructed, new changes take place in the master database, and signals will be sent to SLAVE_IO_THREAD through slave_dump_THREAD, which enhances the real-time performance of master-slave replication.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.