MySQL主备复制数据不一致的情况(2)

|d          | dt                  | t        | ts                  |

+------------+---------------------+----------+---------------------+

|2014-01-10 | 2014-01-10 01:45:19 | 01:45:19 | 2014-01-10 01:45:19 |

| 2015-12-07 | 2015-12-07 14:24:38 | 14:24:38 | 2015-12-07 14:24:38|

+------------+---------------------+----------+---------------------+

2rows in set (0.00 sec)

4、实验三:假设备库数据比主库多的情况,进行数据更新,将产生不一致。

4.1、主库操作:创建表t,插入数据,查看结果

mysql>create table t(id int,name varchar(20));

QueryOK, 0 rows affected (0.01 sec)

mysql>insert into t values(1,'xiao');

QueryOK, 1 row affected (0.00 sec)

mysql>insert into t values(2,'xiao');

QueryOK, 1 row affected (0.02 sec)

mysql>insert into t values(3,'xiao');

QueryOK, 1 row affected (0.01 sec)

mysql>insert into t values(1,'xiao');

QueryOK, 1 row affected (0.01 sec)

mysql>select * from t;

+------+------+

|id  | name |

+------+------+

|    1 | xiao |

|    2 | xiao |

|    3 | xiao |

|    1 | xiao |

+------+------+

4 rowsin set (0.00 sec)

4.2、从库操作:查看结果,插入一条数据(使得备库比主库多一条数据)。

mysql>select * from t;

+------+------+

|id  | name |

+------+------+

|    1 | xiao |

|    2 | xiao |

|    3 | xiao |

|    1 | xiao |

+------+------+

4 rowsin set (0.00 sec)

mysql>insert into t values(1,'huang');

QueryOK, 1 row affected (0.00 sec)

mysql>select * from t;

+------+-------+

|id  | name  |

+------+-------+

|    1 | xiao |

|    2 | xiao |

|    3 | xiao |

|    1 | xiao |

|    1 | huang |

+------+-------+

5 rowsin set (0.00 sec)

4.3、主库操作:把id为1更新为id为10

mysql>update t set id=10 where id=1;

mysql>select * from t;

+------+------+

|id  | name |

+------+------+

|  10 | xiao |

|    2 | xiao |

|    3 | xiao |

|  10 | xiao |

+------+------+

4 rowsin set (0.00 sec)

4.4、从库操作:查询更新结果

mysql>select * from t;

+------+-------+

|id  | name  |

+------+-------+

|  10 | xiao  |

|    2 | xiao |

|    3 | xiao |

|  10 | xiao  |

|  10 | huang |

+------+-------+

5 rowsin set (0.00 sec)

主库更新了两条记录,备库更新了三条记录。从这个实验可以得出,如果主库与备库上下文不一样,那么相同的一条sql在主库与备库执行,产生的效果是不一样,带来了主备数据的不一样。

5、实验四、使用UUID()函数情况,也将使主备库数据不一致

5.1、主库操作

mysql> showvariables like 'binlog_format';

+---------------+-----------+

| Variable_name |Value    |

+---------------+-----------+

| binlog_format |STATEMENT |

+---------------+-----------+

1 row in set (0.00sec)


mysql> createtable test(id varchar(100));

Query OK, 0 rowsaffected (0.01 sec)


mysql> insertinto test values(uuid());

Query OK, 1 rowaffected, 1 warning (0.00 sec)


mysql> select *from test;

+--------------------------------------+

| id                                  |

+--------------------------------------+

| 156bb13f-9cb6-11e5-ab3f-000c29133345 |

+--------------------------------------+

1 row in set (0.00sec)

5.2、从库操作

mysql> showvariables like 'binlog_format';

+---------------+-----------+

| Variable_name |Value    |

+---------------+-----------+

| binlog_format |STATEMENT |

+---------------+-----------+

1 row in set (0.00sec)


mysql> select *from test;

+--------------------------------------+

| id                                  |

+--------------------------------------+

| 1566e5cb-9cb6-11e5-be5b-000c297f9303 |

+--------------------------------------+

1row in set (0.00 sec)

6、实验六、使用user()函数情况,也将使主备库数据不一致

6.1、主库操作

mysql> createtable test(user varchar(100));

ERROR 1050(42S01): Table 'test' already exists

mysql> createtable Atest(user varchar(100));

Query OK, 0 rowsaffected (0.05 sec)


mysql> insertinto Atest values(user());

Query OK, 1 rowaffected, 1 warning (0.01 sec)


mysql> select *from Atest;

+----------------+

| user          |

+----------------+

| root@localhost |

+----------------+

1 row in set (0.00sec)

6.2、从库操作

mysql> select *from Atest;

+------+

| user |

+------+

|      |

+------+

1 row in set (0.00sec)


mysql> selectcount(*) from Atest;

+----------+

| count(*) |

+----------+

|        1 |

+----------+

1 row in set (0.00sec)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/abfecbe90aa6685e9037a3dcdf2a6cbe.html