• MySQL 主从同步架构中你不知道的“坑”(2)


    指定同步库情况

    1、binlog_format= ROW模式‍

    mysql> use testdb;

    Database changed

    mysql> show tables;

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

    | Tables_in_testdb |

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

    | test01      |

    | test1      |

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

    3 rows in set (0.00 sec)

    mysql> insert into test1 values('zhng','man');

    Query OK, 1 row affected (0.05 sec)

    mysql> insert into test1 values('meimei','woman');

    Query OK, 1 row affected (0.04 sec)

    mysql> select * from test1;

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

    | id  | name  |

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

    | zhang | man  |

    | zhng | man   |

    | meimei | woman |

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

    3 rows in set (0.00 sec)

    从库查看

    mysql> use testdb;

    Database changed

    mysql> show tables;

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

    | Tables_in_testdb |

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

    | test01      |

    | test1      |

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

    2 rows in set (0.01 sec)

    mysql> select * from test1;

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

    | id  | name  |

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

    | zhang | man  |

    | zhng | man  |

    | meimei | woman |

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

    3 rows in set (0.01 sec)

    2、binlog_format= STATEMENT模式‍

    主库配置如下

    binlog-do-db = testdb

    从库配置如下

    replicate-wild-do-table = testdb.%

    主库操作

    mysql> create database testdb;

    Query OK, 1 row affected (0.01 sec)

    mysql> use testdb;

    Database changed

    mysql> create table test01 (

        -> id varchar(10) not null,

        -> name varchar(10) not null

        -> );

    Query OK, 0 rows affected (0.04 sec)

    mysql> insert into test01 values('zhang','man');

    Query OK, 1 row affected (0.01 sec)

    mysql> select * from testdb.test01;

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

    | id  | name |

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

    | zhang | man  |

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

    1 row in set (0.00 sec)

    从库查看

    mysql> use testdb;

    Database changed

    mysql> select * from test01;

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

    | id  | name |

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

    | zhang | man  |

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

    1 row in set (0.00 sec)

    测试在不指定忽略库的情况下默认库是否会同步数据

    mysql> create user testdb_user;

    Query OK, 0 rows affected (0.03 sec)

    mysql> select user from mysql.user;

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

    | user    |

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

    | testdb_user |

    | mysql.sys |

    | root    |

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

    [root@mysql-s ~]# mysql -uroot -p -e "select user from mysql.user;"

    Enter password:

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

    | user   |

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

    | mysql.sys |

    | root   |

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

    注:默认的库的数据没有被同步

  • 相关阅读:
    Python该怎么学?
    Python招聘需求
    最短路合集
    最小生成树prim算法
    最小生成树kruskal算法
    React-redux原理探索
    Redux原理探索
    头条前端面试题汇总,会持续更新
    阿里前面面试题(最全),持续更新中
    ASP.Net MVC3/4中Model验证错误信息的本地化
  • 原文地址:https://www.cnblogs.com/duanlinxiao/p/10923118.html
Copyright © 2020-2023  润新知