Setting up replication filters
You can control which tables or databases are to be replicated. On the master, you can control which databases to log changes for by using the --binlog-do-db
and --binlog-ignore-db
options to control binary logging, as mentioned in Chapter 6, Binary Logging. The better way is to control on the slave side. You can execute or ignore statements received from the master by using--replicate-*
options or dynamically by creating replication filters.
How to do it...
To create a filter, you need to execute the CHANGE REPLICATION FILTER
statement.
Replicate a database only
Assume that you want to replicate db1
and db2
only. Use the following statement to create the replication filter.
mysql> CHANGE REPLICATION FILTER REPLICATE_DO_DB = (db1, db2);
Note that you should specify all the databases inside parentheses.
Replicate specific tables
You can specify the tables you want to be replicated using REPLICATE_DO_TABLE
:
mysql> CHANGE REPLICATION FILTER REPLICATE_DO_TABLE = ...