mysql主从复制自增_关于mysql主从复制自增长列
現有兩臺mysql服務器A和B
A:auto_increment_offset = 2
auto_increment_increment = 2
binlog_format="STATEMENT"
B:auto_increment_offset = 1
auto_increment_increment = 2A和B都有如下表,建表語句如下:
test | CREATE TABLE test (
id int(11) NOT NULL AUTO_INCREMENT,
title varchar(45) DEFAULT NULL,
PRIMARY KEY (id)
ENGINE=InnoDB DEFAULT CHARSET=utf8
test1 | CREATE TABLE test1 (
id int(11) NOT NULL AUTO_INCREMENT,
title varchar(45) DEFAULT NULL,
PRIMARY KEY (id)
ENGINE=InnoDB DEFAULT CHARSET=utf8
test表中數據如下:
+----+-------------------------------------
| id | title
+----+-------------------------------------
| 2 | 2
| 4 | 2
| 6 | efe4aee2-e721-11e5-a858-000c2952edc5
| 8 | 2016-03-11 08:31:18
| 10 | 2016-03-11 08:31:40
| 12 | 97621dc2-e722-11e5-a858-000c2952edc5
| 14 | aaaq
| 16 | aaaq
| 18 | 13
+----+-------------------------------------
現在在A服務器執行如下sql:
insert test1 select * from test where id >= 10
雖然mysql出了警告:
Unsafe statement written to the binary log
using statement format since BINLOG_FORMAT = STATEMENT.
但是我看到B服務器同步A服務器數據后顯示如下:
+----+--------------------------------------+
| id | title |
+----+--------------------------------------+
| 10 | 2016-03-11 08:31:40 |
| 12 | 01b889cf-e721-11e5-9568-000c29aa710d |
| 14 | aaaq |
| 16 | aaaq |
| 18 | 13 |
+----+--------------------------------------+
這時候查看A服務器的binlog日志發現
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/*!*/;
A服務器并未提示插入的數據自增長id是多少,為什么B服務器的數據和A服務器的
數據仍然一致。
按自己的理解,B服務器的數據應該是如下,因為是靠B服務器的自己自增長產生id。
+----+--------------------------------------+
| id | title |
+----+--------------------------------------+
| 1 | 2016-03-11 08:31:40 |
| 3 | 01b889cf-e721-11e5-9568-000c29aa710d |
| 5 | aaaq |
| 7 | aaaq |
| 9 | 13 |
求各位師兄解答下為什么,謝謝!
總結
以上是生活随笔為你收集整理的mysql主从复制自增_关于mysql主从复制自增长列的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么拆掉墙上粘的石膏线?
- 下一篇: linux cmake编译源码,linu