1、过滤器概述
主数据库只复制给从数据库一部分数据给从节点,而不是复制全部内容;复制过滤器可以设置有哪些数据可以复制到从节点,类似于“白名单”,哪些数据是不可以进行复制,类似“黑名单”。
复制过滤器有两种实现机制:一种是在主库进行配置,一种是在从库上配置。然而第一种一般不会使用,因为如果在主库上配置过滤器,那么主库的二进制日志记录的便只有某一个数据库的信息,而不会记录其他库的信息,这样如果发生故障进行数据恢复时就没办法从二进制日志进行重放恢复。
所以一般会采用第二种方式,在从库上配置过滤器,但是也有缺点,就是增加IO读写的压力,因为主节点记录所有库的二进制日志信息依然会被从节点IO线程读取,并存储在从节点的中继日志中,由于设置了过滤,在从节点执行SQL线程时只会重放未被过滤掉的操作。
2、实验配置
1)先配置数据库主从
主库配置:
[root@www ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
log_bin=master-bin
server_id=1
[root@www ~]# systemctl restart mariadb.service
[root@www ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant replication slave,replication client on *.* to 'jyy'@'192.168.126.135' identified by 'jyy';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
从库配置:
[root@www ~]#vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
server_id=3
relay_log=relay-log
[root@www ~]# systemctl restart mariadb.service
[root@www ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and