Understanding of server-id during mysql Replication

Source: Internet
Author: User

Understanding of server-id during mysql replication 1. What is server-id used? Do you know? 1. the synchronized data of mysql contains the server-id, which is used to identify the server from which the statement was originally written, therefore, the server-id must have 2. Each slave in synchronization corresponds to a master thread on the master, which is identified by the server-id of the slave; each slave can have at most one master thread on the master end. If two slave servers have the same-id, the first one will be kicked off when the last connection is successful. There is at least one such consideration: After slave actively connects to the master, if slave stop is executed on the slave, the connection is disconnected, but the corresponding thread on the master has not exited; after slave start, the master cannot create another thread and keep the original thread, So synchronization may be faulty. 3. When the mysql master is synchronizing data, multiple masters need to form a ring, but during synchronization, it is necessary to ensure that a piece of data will not fall into an endless loop. Here is the implementation of server-id. in my. setting the server ID in cnf is a necessary step to implement or start replication. The general rule is that the ID of the MySQL replication server must be unique throughout the environment. Generally, multi-master/circular replication is performed simultaneously. We set the log option from updated to 1. Therefore, when any declaration is made, the master's slave will be executed and it will be recorded in the binary log of the server. For example, we have three servers A, B, and C. The server IDs are 11, 22, and 33. They are copying the cyclic mode (Multi-master), for example, A is the master server B, B is the master of the C server and C is the master of A server. At present, any MySQL client will execute the insert/update/delete server Declaration, which will be recorded in the binary server and server ID 11. Because the statement is recorded on a binary server, it will go to server B (because B is a slave), where the execution and record of binlog B server are on the same server ID 11. (Why is the same server ID? Because of this statement, the execution is performed on the server and server ID 11 and server B initiated by the mysql client with an irregular SQL thread ). Now this statement will go to the C server again (because C is the slave of B), where the C server recorded in the binary log executed in the same server ID 11. Because C is the master server, the C server that comes with this statement will pass the binary log server. The SQL thread of a server will compare the server ID and will find that, as indicated by 11, this is because the server that was initially initiated and there is no need to execute the SQL thread, so this statement will be skipped at last. With the server ID, we can avoid replication on the master-master/circular in case of endless loops. 3. Make sure that the [mysqld] section of the my. cnf file on the master server host contains a log-bin option. This part should also have a server-id = Master_id option, where master_id must be a positive integer between 1 and 232-1. Example: 6. [mysqld] 7. log-bin = mysql-bin8. server-id = 1 if those options are not provided, add them and restart the server. 9. stop the slave server and. add the following lines to the cnf file: 10. [mysqld] 11. the server-id = slave_idslave_id value is the same as the Master_id value. It must be a positive integer between 1 and 232-1. In addition, the slave server ID must be different from the master server ID. For example: [mysqld] server-id = 2 if multiple slave servers are set, each slave server must have a unique server-id value, it must be different from the master server and other slave servers. Server-id values are considered similar to IP addresses: These ID values can uniquely identify each server instance in a replication server cluster. If no server-id value is specified, if no master-host is defined, set it to 1; otherwise, set it to 2. Note that if the server-id is too long, the master server rejects all connections from the slave server, and the slave server rejects connection to the master server. In this way, the omitted server-id is only applicable to binary log backup.

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.