MySQL extension-replication Overview

Source: Internet
Author: User

Http://aronlulu.iteye.com/blog/790641

MySQL is widely used in the Internet. A large part of the reason is its replication mechanism, which is simple and practical. It can easily improve the performance of several PC hosts and is a must-have solution for small and medium websites.

First, under what circumstances should we expand the database, create a website, and create a database? One day the WebSite becomes popular, and the traffic volume increases, which means there are more connections to read webpages from your server, i/O bottlenecks are coming. Naturally, I want more.
Add a few machines to share the pressure, but the data must be consistent with the data in the database on the source host. At this time, when the database is expanded, replication will start to work.

Implementation Mechanism of Replication

The first step is that the master must open the binary log, which contains various operation records of the database. The slave connects to the master host through the IO thread and requests the log Content, this request should also contain the log request location, that is, the log starting from where.

Step 2 after the master receives the request, it starts to return the content to slave through the IO thread. Besides the log content, the returned content should also include the location of the log file and the next time from where to obtain the new log.

Step 3: The slave Io thread records the obtained content to the relay log file on the local machine, and the location content is recorded in the master-info file, so that the log Content of the master can be quickly located next time.

Step 4 is to parse the log Content and execute the log, so that the master and slave data are synchronized.

It is worth noting that step 3 and Step 4 are executed simultaneously (early MySQL was executed separately) and two threads (I/O thread and SQL thread) are executed asynchronously, the advantage of this is nothing more than reducing the synchronization time and changing the space for time, reducing the probability of data loss.

This is the communication process between a master machine and a slave machine.

In actual use, it is obviously impossible to have only one slave. There are several main cluster methods.

Master-slaves

One master is the simplest cluster mode for multiple slaves instances. The principle is the same as the preceding

Master-Master

Two masters. This architecture is mainly used to solve the Hot Standby problem. It can prevent the master from being down and lead to the need to re-deploy slaves. Here there is a problem:
Master means that both sides should provide the Read and Write functions. In actual operations, the same table should be prevented from providing the write function on both sides of the master. This will lead to dirty data.
Write on master1, and write some tables on master2.

Master-slaves (cascade replication Architecture)

The purpose of this architecture is also very clear. The general master-salves architecture requires a large number of I/O threads to connect to the master node as the number of server load balancers increases.
The master has to provide the write service externally. The pressure is too high. This architecture is to decompress the master, transfer the I/O to slaves, and then slaves to the second slaves.
When I/O services are provided, the disadvantage is also obvious, and the delay is serious.

Master-master-slaves

This is the most complex, secure, and stable, so we can combine the second and third types.

The above are common vertical extension architectures, which mainly solve the problem of large-scale concurrent reading. As for concurrent writing, MySQL DATA splitting is required and data writing will be performed tomorrow.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.