微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

replicate-rewrite-db和Replicate_Wild_Do_Table如何实现表级别映射复制

这期内容当中小编将会给大家带来有关replicate-rewrite-db和Replicate_Wild_Do_Table如何实现表级别映射复制,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

将3306实例下sakila的两张表actor同步到5725实例下的ming数据库中。

初始化数据

mysqldump -uroot -poracle -q --single-transaction -n -B sakila --tables actor --master-data=2 > sakila.sql

注意添加-n,不生成创建database的语句。

MysqL> create database ming;

Query OK, 1 row affected (0.00 sec)

MysqL> use ming

Database changed

MysqL> source /root/sakila.sql

修改从库参数文件,并重启从库

添加

replicate-rewrite-db = sakila -> ming

CHANGE MASTER TO

MASTER_HOST='192.168.61.2',

MASTER_USER='repl',

MASTER_PASSWORD='oracle',

MASTER_LOG_FILE='MysqL-bin.000013',

MASTER_LOG_POS=154;

如果只添加replicate-rewrite-db这个参数,只是实现了数据库级别的复制,还不是表级别。这样会很容易复制其他操作到从库,导致sql thread报错。

比如主库执行

MysqL> use sakila

MysqL> create table actor_bak like actor;

Query OK, 0 rows affected (0.31 sec)

MysqL> insert into actor_bak select * from actor;

Query OK, 200 rows affected (0.17 sec)

Records: 200  Duplicates: 0  Warnings: 0

MysqL> update tt.test01 set c2=10 where c1=9;

Query OK, 1 row affected (0.12 sec)

Rows matched: 1  Changed: 1  Warnings: 0

有关actor_bak的动作会被传递到从库。但是从库没有tt数据库,那么就会sql thread进程就会报错。

Last_sql_Error: Error 'UnkNown database 'tt'' on query. Default database: 'ming'. Query: 'create table tt.t1 like actor_bak'

所以完整的写法应该是;

replicate-rewrite-db = sakila -> ming

replicate-wild-do-table=ming.actor

主库执行

MysqL> use sakila

MysqL> insert into  tt.t1 select * from actor_bak;                

Query OK, 200 rows affected (0.00 sec)

Records: 200  Duplicates: 0  Warnings: 0

从库不会再报错。

添加如上参数后,可以在show slave status中看到。

MysqL [localhost] {msandBox} ((none))   > show slave status\G

*************************** 1. row   ***************************

               Slave_IO_State: Waiting for   master to send event

                  Master_Host: 192.168.61.2

                  Master_User: repl

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File:   MysqL-bin.000013

            Read_Master_Log_Pos: 9815

               Relay_Log_File:   relay-bin.000004

                Relay_Log_Pos: 4683

          Relay_Master_Log_File: MysqL-bin.000013

             Slave_IO_Running: Yes

            Slave_sql_Running: Yes

              Replicate_Do_DB:

            Replicate_Ignore_DB:

             Replicate_Do_Table:

         Replicate_Ignore_Table:

        Replicate_Wild_Do_Table:   ming.actor

    Replicate_Wild_Ignore_Table:

                   Last_Errno: 0

                   Last_Error:

                 Skip_Counter: 0

            Exec_Master_Log_Pos: 9815

              Relay_Log_Space: 4884

              Until_Condition: None

               Until_Log_File:

                Until_Log_Pos: 0

             Master_SSL_Allowed: No

             Master_SSL_CA_File:

             Master_SSL_CA_Path:

              Master_SSL_Cert:

            Master_SSL_Cipher:

               Master_SSL_Key:

          Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

                Last_IO_Errno: 0

                Last_IO_Error:

               Last_sql_Errno: 0

               Last_sql_Error:

    Replicate_Ignore_Server_Ids:

             Master_Server_Id: 1051295

                  Master_UUID:   4c312339-ab38-11e9-86a8-000c29050245

             Master_Info_File:   /root/sandBoxes/msb_5_7_25/data/master.info

                    sql_Delay: 0

            sql_Remaining_Delay: NULL

        Slave_sql_Running_State: Slave has read all relay log; waiting for   more updates

             Master_Retry_Count: 86400

                  Master_Bind:

        Last_IO_Error_Timestamp:

       Last_sql_Error_Timestamp:

               Master_SSL_Crl:

             Master_SSL_Crlpath:

             Retrieved_Gtid_Set:

            Executed_Gtid_Set:

                Auto_Position: 0

           Replicate_Rewrite_DB:   (sakila,ming)

                 Channel_Name:

             Master_TLS_Version:

1 row in set (0.00 sec)

在线修改参数前,需要先暂停sql thread进程:

MysqL [localhost] {msandBox} ((none)) >  stop slave sql_thread;

Query OK, 0 rows affected (0.00 sec)

MysqL [localhost] {msandBox} ((none)) > change replication filter replicate_rewrite_db=((sakila,ming));

Query OK, 0 rows affected (0.00 sec)

MysqL [localhost] {msandBox} ((none)) > start slave sql_thread;

Query OK, 0 rows affected (0.00 sec)

Remove参数

CHANGEREPLICATIONFILTER    REPLICATE_DO_DB=(),REPLICATE_IGnorE_DB=();

其它写法:

CHANGE REPLICATION FILTER

REPLICATE_WILD_IGnorE_TABLE = ('db1.new%', 'db2.new%');

如果相同的过滤规则出现了多次,那么只有最后一个规则会生效:

CHANGE REPLICATION FILTER

REPLICATE_DO_DB = (db1, db2), REPLICATE_DO_DB = (db3, db4);

CHANGE REPLICATION FILTER

REPLICATE_DO_DB = (db3,db4);

CHANGE REPLICATION FILTER

    REPLICATE_DO_DB = (d1), REPLICATE_IGnorE_DB = (d2);

上述就是小编为大家分享的replicate-rewrite-db和Replicate_Wild_Do_Table如何实现表级别映射复制了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注编程之家行业资讯频道。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐