MySQL per channel replication filters examples

This is a simple article with an examples for “how to configure replication filters for channel”

Starting from MySQL 8.0 replication filters can be global or channel-specific, enabling you to configure multi-source replicas with replication filters on specific replication channels. Channel specific replication filters are particularly useful in a multi-source replication topology when the identical database or table is present on multiple sources, and the replica is only required to replicate it from one source.

Example:

CHANGE REPLICATION FILTER REPLICATE_DO_DB =(test,test3,test4 ), REPLICATE_REWRITE_DB = ((test1,test3),(test2,test4)) FOR CHANNEL "node1";

my.cnf confiration to make replication filter setting persistent:

replicate-do-db=node1:test
replicate-do-db=node1:test3
replicate-do-db=node1:test4
replicate-rewrite-db=node1:test1->test3
replicate-rewrite-db=node1:test2->test4
mysql > show slave status\G
Slave_IO_State: Waiting for master to send event
Master_Host: 127.0.0.1
Master_User: msandbox
Master_Port: 23229
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 7504
Relay_Log_File: mysql-relay-node1.000013
Relay_Log_Pos: 324
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test,test3,test4
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 7504
Relay_Log_Space: 535
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: 1
Master_UUID: 00023229-1111-1111-1111-111111111111
Master_Info_File: mysql.slave_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: (test1,test3),(test2,test4)
Channel_Name: node1
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:

Few more examples:

per-channel filters setting:

replicate-do-db=channel_name:test
replicate-do-db=channel_name:my_db2
replicate-do-db=channel_name:my_db3
replicate-ignore-db=channel_name:db1
replicate-ignore-db=channel_name:db11
replicate-ignore-db=channel_name:my_db6
replicate-do-table=channel_name:test.t1
replicate-do-table=channel_name:test.t2
replicate-ignore-table=channel_name:test.t11
replicate-ignore-table=channel_name:test.t22
replicate-wild-do-table=channel_name:test.t%
replicate-wild-do-table=channel_name:test.s%
replicate-wild-ignore-table=channel_name:test.m%
replicate-wild-ignore-table=channel_name:test.n%
replicate-rewrite-db=channel_name:my_db7->rewrite_db7
replicate-rewrite-db=channel_name:my_db8->rewrite_db8

Reference: https://dev.mysql.com/doc/refman/8.0/en/replication-rules-channel-based-filters.html