溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

replicate-rewrite-db和Replicate_Wild_Do_Table如何實(shí)現(xiàn)表級(jí)別映射復(fù)制

發(fā)布時(shí)間:2021-11-03 15:21:10 來源:億速云 閱讀:414 作者:柒染 欄目:MySQL數(shù)據(jù)庫

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)replicate-rewrite-db和Replicate_Wild_Do_Table如何實(shí)現(xiàn)表級(jí)別映射復(fù)制,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

將3306實(shí)例下sakila的兩張表actor同步到5725實(shí)例下的ming數(shù)據(jù)庫中。

初始化數(shù)據(jù)

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

注意添加-n,不生成創(chuàng)建database的語句。

mysql> create database ming;

Query OK, 1 row affected (0.00 sec)

mysql> use ming

Database changed

mysql> source /root/sakila.sql

修改從庫參數(shù)文件,并重啟從庫

添加:

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這個(gè)參數(shù),只是實(shí)現(xiàn)了數(shù)據(jù)庫級(jí)別的復(fù)制,還不是表級(jí)別。這樣會(huì)很容易復(fù)制其他操作到從庫,導(dǎo)致sql thread報(bào)錯(cuò)。

比如主庫執(zhí)行

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

有關(guān)actor_bak的動(dòng)作會(huì)被傳遞到從庫。但是從庫沒有tt數(shù)據(jù)庫,那么就會(huì)sql thread進(jìn)程就會(huì)報(bào)錯(cuò)。

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

所以完整的寫法應(yīng)該是;

replicate-rewrite-db = sakila -> ming

replicate-wild-do-table=ming.actor

主庫執(zhí)行

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

從庫不會(huì)再報(bào)錯(cuò)。

添加如上參數(shù)后,可以在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)

在線修改參數(shù)前,需要先暫停SQL thread進(jìn)程:

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參數(shù)

CHANGEREPLICATIONFILTER    REPLICATE_DO_DB=(),REPLICATE_IGNORE_DB=();

其它寫法:

CHANGE REPLICATION FILTER

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

如果相同的過濾規(guī)則出現(xiàn)了多次,那么只有最后一個(gè)規(guī)則會(huì)生效:

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如何實(shí)現(xiàn)表級(jí)別映射復(fù)制了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI