2台在线linux 主机器(a , b)  mysql 都有。
一台机器a有一个表user30万 数据
机器b有同样结构的表user 只有7万    (这7万是完全属于a机器的user的)现在要求做到2个mysql 数据完全同步, 当a 机器的user 增加修改或者删除的时候
b机器 user有对应部分的id  能相应的 增加修改或者删除  (比如 字段groupId=8的a 机器 和b机器的数据要完全同步)b机器的user表任何修改  a机器要对应修改。
这个请问如何mysql如何实现 (选择性复制)

解决方案 »

  1.   

    请问 mysql 可以实现视图复制???
      

  2.   

    16.4.1.26. Replication and ViewsViews are always replicated to slaves. Views are filtered by their own name, not by the tables they refer to. This means that a view can be replicated to the slave even if the view contains a table that would normally be filtered out by replication-ignore-table rules. Care should therefore be taken to ensure that views do not replicate table data that would normally be filtered for security reasons. 
    现在不知道如何使用如果是表复制
    replication-table=mydb.user;我的视图内容为select * from user where grouid=8;请问可以设置为这样吗
    replication-view=mydb.user
      

  3.   

    自己定程序来完全比较方便。一般设想就是通过BINLOG,把今天机器A上的USER表的修改SQL语句都取出。 然后再到B机中执行。
      

  4.   

    选择 user表的  groupId=8  纪录进行更新这个如何实现   (不是表粒度的  已经到行)
      

  5.   

    视图复制 在 mysql 只是提了下,
    <<< Views are always replicated to slaves. Views are filtered by their own name, not by the tables they refer to. This means that a view can be replicated to the slave even if the view contains a table that would normally be filtered out by replication-ignore-table rules. Care should therefore be taken to ensure that views do not replicate table data that would normally be filtered for security reasons.
    maser  user
             user_view
    slave   user头疼slave的配置replication-view=mydb.user_view
    这个视图的变化如何到从机器的user表 还需要找如何实   (楼上帮忙看)
      

  6.   

    用MYSQL的复制就可以做到呀。你说的选择性的复制,没明白什么意思。
      

  7.   

    user 表的部分数据  (字段groupId=8) 只有这些行的数据需要同步。不需要整个表同步  (b 机器不能看到所有a 表的数据信息)  
      

  8.   

    请问 视图复制 有人做过没有 ???maser  表  user
           视图  user_view
    slave   user头疼slave的配置replication-view=mydb.user_view
    这个视图的变化如何到从机器的user表 还需要找如何实现
    我的视图内容为select * from user where grouid=8;请问可以设置为这样吗
    replication-view=mydb.user-------------不知道如何把视图 的内容 传递给 b机器 
      

  9.   

    何必搞得这么复杂,你在从库的表里加个触发器,只允许grouid=8的插入,其他插入都忽略掉。
      

  10.   


        drop trigger if exists isa;
    CREATE DEFINER=`cpc`@`localhost` TRIGGER `dbbin`.`isa` BEFORE INSERT ON dbbin.t1 FOR EACH ROW
    BEGIN
        if new.a<10 then
            insert into t1 values(12);
        end if;
    END;类似这样的。只能插入10以下的数。
      

  11.   

    我现在想实现【mysql 性能调优与架构设计】的级联slave
    结果发现失败架构如下  master a  --------> slave  b -------> slave  c
                         (这个机器调整my.cnf 产生binlog)    
    实际调整a b  c 3台机器的my.cnf, 最后得到如下
    a 主
    b 主从  从连接a
    c 从    从连接b测试结果发现  a的数据更新能够及时到 b,  但c不能得到a的变化。  复制不能传递(现在发现)。 
                  (现在发现b机器的如果做数据更新, c上能实时收到b的数据更新) 如何能实现复制的级联更新?? (c上能接受a的数据的实时变化,如果能做该如何配置3个机器的my.cnf)  
                     
      

  12.   

    log_slave_updates=1添加这个到MYSQLD下。
      

  13.   

    log_slave_updates=1 测试通过 感谢zuoxingyu现在有个大问题 
    请问 视图复制 有人做过没有 ???maser 表 user
      视图 user_view
    slave user头疼slave的配置replication-view=mydb.user_view
    这个视图的变化如何到从机器的user表 还需要找如何实现
    我的视图内容为select * from user where grouid=8;请问可以设置为这样吗
    replication-view=mydb.user-------------不知道如何把视图 的内容 传递给 b机器 
    (已经能够做 级联复制+触发器
    但是我的复制表高达27个, 这样每个表写触发器非常麻烦 27×3=81,几乎快100多个,而且维护好麻烦。
    诚意想知道 mysql下 的 replication-view如何在2台主从机器之间实现
      

  14.   

    replication-view=mydb.user明确没有这样东西。
    你去看看复制的机制,复制是基于2进制日志的,对表的修改操作会写入日志文件。而视图是基于表的一个查询子集。。你的目的是复制只选择主库上某些表的某些行进行复制,暂时还没想到好办法。