About mysql master-slave replication auto-increment columns

Source: Internet
Author: User
There are two mysql servers A and BA: Creating & quot; STATEMENT & quot; B: auto_increment_offset1auto_increment_increment2A and B. The table creation statements are as follows: test | CREATETABLE 'test' ('id' int (11) NOTNULLAUTO_INCREMENT, mysql

Two mysql servers A and B
A: auto_increment_offset = 2
Auto_increment_increment = 2
Binlog_format = "STATEMENT"
B: auto_increment_offset = 1
Auto_increment_increment = 2

Both A and B are shown in the following table. The table creation statement is as follows:

Test | CREATE TABLEtest(
idInt (11) not null AUTO_INCREMENT,
titleVarchar (45) default null,
Primary key (id)
ENGINE = InnoDB default charset = utf8

Test1 | CREATE TABLEtest1(
idInt (11) not null AUTO_INCREMENT,
titleVarchar (45) default null,
Primary key (id)
ENGINE = InnoDB default charset = utf8

The data in the test table is as follows:

+ ---- + -------------------------------------
| Id | title
+ ---- + -------------------------------------
| 2 | 2
| 4 | 2
| 6 | efe4aee2-e721-11e5-a858-000c2952edc5
| 8 | 08:31:18
| 10 | 08:31:40
| 12 | 97621dc2-e722-11e5-a858-000c2952edc5
| 14 | aaaq
| 16 | aaaq
| 18 | 13
+ ---- + -------------------------------------

Run the following SQL statement on server:
Insert test1 select * from test where id> = 10

Although mysql has a warning:
Unsafe statement written to the binary log

Using statement format since BINLOG_FORMAT = STATEMENT.

However, I can see that server B synchronizes the data of server A as follows:
+ ---- + ---------------------------------------- +
| Id | title |
+ ---- + ---------------------------------------- +
| 10 | 08:31:40 |
| 12 | 01b889cf-e721-11e5-9568-000c29aa710d |
| 14 | aaaq |
| 16 | aaaq |
| 18 | 13 |
+ ---- + ---------------------------------------- +

At this time, check the binlog log of server A and find
BEGIN
/*! */;

At 665994732

#160314 15:47:15 server id 136 end_log_pos 665994865 CRC32 0xeb828757 Query thread_id = 1675059 exec_time = 0 error_code = 0
Set timestamp = 1457941635 /*! */;
Insert test1 select * from test where id> = 10
/*! */;

At 665994865

#160314 15:48:38 server id 136 end_log_pos 665994896 CRC32 0x5a745662 Xid = 169785483
COMMIT /*! */;

Server A does not prompt how many IDs are inserted for auto-increment data. why are the data of server B and server A's
The data is still consistent.
According to your understanding, the data of server B should be as follows, because the id is generated by the self-growth of server B.
+ ---- + ---------------------------------------- +
| Id | title |
+ ---- + ---------------------------------------- +
| 1 | 08:31:40 |
| 3 | 01b889cf-e721-11e5-9568-000c29aa710d |
| 5 | aaaq |
| 7 | aaaq |
| 9 | 13 |

Thank you for your answers!

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.