Mariadb之复制过滤器

  mariadb的主从复制集群,默认情况下是把主库上的所有库进行复制,只要在主库上产生写操作,从库基于主库的二进制日志做重放,从而实现把主库的上的库表复制到从库;复制过滤器指的是我们仅复制一个或几个数据库相关的数据,而非所有;过滤器的作用就是来定义我们要复制那些库,那些表,这种定义过滤器的方式叫白名单机制;除了这种告诉服务器我们要复制的库表的,当然我们也可以告诉服务器我们不需要复制的库或表,或者需要忽略的库表的机制叫黑名单;在定义我们需要复制的库或者表,我们可以在主库上定义,也可以在从库上定义;不同的是在主库上定义,我们只能定义需要复制的那些库,忽略那些库;其实在主库上定义过滤器,就是告诉主库那些库的操作不记录二进制日志,当然在主库上不记录二进制,也就无法实现复制;这种在主库上定义那些库记录二进制,那些库不记录二进制,这种方式不是很推荐,原因在于如果主库宕机,做恢复操作时,我们不能利用二进制日志来把数据全部恢复;通常情况下我们在从库上定义复制那些库或者忽略那些库,这里需要注意一点,我们要么使用白名单机制,要么使用黑名单机制,不建议混合使用;

  在主库上配置只允许某些库记录二进制日志,用binlog_do_db变量来指定,如下

  提示:以上配置表示只记录和first_db库相关写操作的事件到二进制日志中;

  重启主库,然后在主库上创建其他库,看看是否还会同步到从库呢?

  提示:可以看到我们重启主库后,在主库上新建mydb库,在从库上并没有看到mydb从主库上复制过来;

  在主库上操作first_db库,看看是否及时同步到从库呢?

  提示:可以看到在主库上操作first_db中的表,在从库上是能够及时的看到;

  配置在主库上忽略某些库,剩余所有库都记录二进制日志

  提示:以上配置表示忽略first_db库上的二进制日志记录,剩余其他库都要做二进制日志记录;

  测试:重启主库,在主库上操作first_db库,看看是否能够及时同步到从库?

  提示:可以看到我们在主库上操作first_db库中的student表,没有被同步到从库的;

  查看主库是binlog否记录了我们刚才的插入操作的语句

  提示:在主库上看二进制日志,并没有记录我们刚才的插如语句相关的操作;

  在主库上操作其他库看看是否能够被同步到从库呢?

  提示:可以看到我们在主库上创建新的库表是能够及时同步到从库;

  在从库上配置只复制first_db相关写操作事件

[root@docker-node03 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 22
Server version: 5.5.65-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)]> show global variables like 'replicate%';
+----------------------------------+-----------+
| Variable_name                    | Value     |
+----------------------------------+-----------+
| replicate_annotate_row_events    | OFF       |
| replicate_do_db                  |           |
| replicate_do_table               |           |
| replicate_events_marked_for_skip | replicate |
| replicate_ignore_db              |           |
| replicate_ignore_table           |           |
| replicate_wild_do_table          |           |
| replicate_wild_ignore_table      |           |
+----------------------------------+-----------+
8 rows in set (0.00 sec)

MariaDB [(none)]> set @@global.replicate_do_db=first_db;
ERROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first
MariaDB [(none)]> stop slave;
Query OK,0 rows affected (0.01 sec)

MariaDB [(none)]> set @@global.replicate_do_db=first_db;
Query OK,0 rows affected (0.01 sec)

MariaDB [(none)]> show global variables like 'replicate%';
+----------------------------------+-----------+
| Variable_name                    | Value     |
+----------------------------------+-----------+
| replicate_annotate_row_events    | OFF       |
| replicate_do_db                  | first_db  |
| replicate_do_table               |           |
| replicate_events_marked_for_skip | replicate |
| replicate_ignore_db              |           |
| replicate_ignore_table           |           |
| replicate_wild_do_table          |           |
| replicate_wild_ignore_table      |           |
+----------------------------------+-----------+
8 rows in set (0.00 sec)

MariaDB [(none)]> start slave;
Query OK,0 rows affected (0.00 sec)

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.0.22
                  Master_User: rpluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000017
          Read_Master_Log_Pos: 245
               Relay_Log_File: relay-log.000035
                Relay_Log_Pos: 529
        Relay_Master_Log_File: mysql-bin.000017
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: first_db
          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: 245
              Relay_Log_Space: 1101
              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
1 row in set (0.00 sec)

MariaDB [(none)]> 

  提示:以上是在从节点上直接在线修改replicate_do_db变量来实现复制过滤功能;如果需要永久生效,那么把该配置写到配置文件中即可;以上配置表示只复制first_db相关写操作的事件;在线修改变量的方式,需要先停止slave,修改完成后在启动;从show slave status中,我们就能够清楚的replicate_do_db的值为first_db;

  测试:在主库上对其他库操作,看看是否能够同步到从节点?

  提示:可以看到我们在主库删除mydb2中的test表后,并没有同步到从库;

  测试:操作first_db中的表,看看是否能同步?

  提示:可以看到我们在first_db库中的student表中插入了一条新数据,在从库是能够及时的同步;

  配置从节点只复制first_db库中的student表的操作相关事件

MariaDB [first_db]> stop slave;
Query OK,0 rows affected (0.01 sec)

MariaDB [first_db]> show global variables like 'replicate%';
+----------------------------------+-----------+
| Variable_name                    | Value     |
+----------------------------------+-----------+
| replicate_annotate_row_events    | OFF       |
| replicate_do_db                  | first_db  |
| replicate_do_table               |           |
| replicate_events_marked_for_skip | replicate |
| replicate_ignore_db              |           |
| replicate_ignore_table           |           |
| replicate_wild_do_table          |           |
| replicate_wild_ignore_table      |           |
+----------------------------------+-----------+
8 rows in set (0.00 sec)

MariaDB [first_db]> set @@global.replicate_do_table=first_db.student;
ERROR 1232 (42000): Incorrect argument type to variable 'replicate_do_table'
MariaDB [first_db]> set @@global.replicate_do_table='first_db.student';
Query OK,0 rows affected (0.00 sec)

MariaDB [first_db]> show global variables like 'replicate%';           
+----------------------------------+------------------+
| Variable_name                    | Value            |
+----------------------------------+------------------+
| replicate_annotate_row_events    | OFF              |
| replicate_do_db                  | first_db         |
| replicate_do_table               | first_db.student |
| replicate_events_marked_for_skip | replicate        |
| replicate_ignore_db              |                  |
| replicate_ignore_table           |                  |
| replicate_wild_do_table          |                  |
| replicate_wild_ignore_table      |                  |
+----------------------------------+------------------+
8 rows in set (0.00 sec)

MariaDB [first_db]> start slave;
Query OK,0 rows affected (0.00 sec)

MariaDB [first_db]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.0.22
                  Master_User: rpluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000017
          Read_Master_Log_Pos: 1198
               Relay_Log_File: relay-log.000050
                Relay_Log_Pos: 529
        Relay_Master_Log_File: mysql-bin.000017
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: first_db
          Replicate_Ignore_DB: 
           Replicate_Do_Table: first_db.student
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1198
              Relay_Log_Space: 1101
              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
1 row in set (0.00 sec)

MariaDB [first_db]> 

  提示:replicate_do_table这个变量在线修改时需要指明那个库中的那个表,并用引号引起来,否则会提示我们参数类型不正确;

  测试:在主库的first_db库中新建一张表,看看是否能够被同步到从库?

  提示:可以看到我们在主库的fisrt_db中新建一张test表,并没有同步到从库中去,这说明replicate_do_table的优先级要高于replicate_do_db;

  在主库的first_db库中对student表做插入操作,看看是否能够被同步到从库?

  提示:可以看到操作first_db中的student是能够及时同步到从库;

  设置从节点只复制以student开头的表

MariaDB [first_db]> stop slave;
Query OK,0 rows affected (0.00 sec)

MariaDB [first_db]> show global variables like 'replicate%';
+----------------------------------+------------------+
| Variable_name                    | Value            |
+----------------------------------+------------------+
| replicate_annotate_row_events    | OFF              |
| replicate_do_db                  | first_db         |
| replicate_do_table               | first_db.student |
| replicate_events_marked_for_skip | replicate        |
| replicate_ignore_db              |                  |
| replicate_ignore_table           |                  |
| replicate_wild_do_table          |                  |
| replicate_wild_ignore_table      |                  |
+----------------------------------+------------------+
8 rows in set (0.00 sec)

MariaDB [first_db]> set @@global.replicate_wild_do_table='first_db.student%';
Query OK,0 rows affected (0.00 sec)

MariaDB [first_db]> show global variables like 'replicate%';                 
+----------------------------------+-------------------+
| Variable_name                    | Value             |
+----------------------------------+-------------------+
| replicate_annotate_row_events    | OFF               |
| replicate_do_db                  | first_db          |
| replicate_do_table               | first_db.student  |
| replicate_events_marked_for_skip | replicate         |
| replicate_ignore_db              |                   |
| replicate_ignore_table           |                   |
| replicate_wild_do_table          | first_db.student% |
| replicate_wild_ignore_table      |                   |
+----------------------------------+-------------------+
8 rows in set (0.01 sec)

MariaDB [first_db]> start slave;
Query OK,0 rows affected (0.00 sec)

MariaDB [first_db]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.0.22
                  Master_User: rpluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000017
          Read_Master_Log_Pos: 1198
               Relay_Log_File: relay-log.000051
                Relay_Log_Pos: 529
        Relay_Master_Log_File: mysql-bin.000017
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: first_db
          Replicate_Ignore_DB: 
           Replicate_Do_Table: first_db.student
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: first_db.student%
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1198
              Relay_Log_Space: 1101
              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
1 row in set (0.00 sec)

MariaDB [first_db]> 

  测试:在主库first_db库中操作非student开头的表,看看是否能够被复制到从库呢?

  提示:可以看到在主库的first_db库中新增test2表,并没有被同步到从库;

  测试:在主库新增student_test表,看看是否被同步到从库?

  提示:可以看到在主库上新建student_test表被同步到从库中去了;

  以上就是mariadb/mysql数据库主从复制中的复制过滤器的使用;以上演示部分使用白名单机制进行演示的,黑名单和白名单配置方式相同,只不过黑名单表示忽略指定的库或者表,其他剩下的库和表都要进行复制,而白名单是指定的库和表都要复制,其他剩余的库或表都不被复制;在从节点使用黑名单机制忽略库使用replicate_ignore_db变量指定;忽略某些表使用replicate_ignore_table变量来指定;忽略以某类表使用replicate_ignore_wild_do_table指定;使用方式和上面白名单机制的使用方式一样;如果需要永久生效,请把以上变量写到配置文件中重启服务即可生效;

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

相关推荐


安装开始...1.打开“https://dev.mysql.com/downloadsepo/yum/”下载Mysql源      将下载好的mysql源上传linux服务器 2.yumlocalinstallmysql80*#安装源 centos7中默认安装的是mariadb数据库,如果想要安装mysql,首先要移除mariadb;
安装Helm3#官网下载慢#wgethttps://get.helm.sh/helm-v3.5.4-linux-amd64.tar.gzwgethttp://qiniu.dev-share.top/helm-v3.5.4-linux-amd64.tar.gztar-zxvfhelm-v3.5.4-linux-amd64.tar.gzcplinux-amd64/helm/usr/local/bin#查看helmclient版本helmversion
通过Linux命令行启动用的指令:systemctlstartmariadb.service反馈:Failedtostartmariadb.service:Unitmariadb.servicenotfound.MariaDB简介MariaDB是MySQL的一个分支,MariaDB打算保持与MySQL的高度兼容性,确保具有库二进制奇偶校验的直接替换功能,以及与MySQLAPI和命令
InstallingMariaDBServer10.4TodeployMariaDBCommunityServer10.4onRHEL7orCentOS7,firstdownloadandusethe mariadb_repo_setup scripttoconfiguretheMariaDBrepositoriesforYUM:$sudoyuminstallwget$wgethttps://downloads.mariadb.com/
阅读目录一什么是存储引擎二mysql支持的存储引擎三使用存储引擎一什么是存储引擎mysql中建立的库--> 文件夹库中建立的表--> 文件现实生活中我们用来存储数据的文件有不同的类型,每种文件类型对应各自不同的处理机制:比如处理文本用txt类型,处理表格用excel,处理图片
1、安装MariaDB安装命令yum-yinstallmariadbmariadb-server安装完成MariaDB,首先启动MariaDBsystemctlstartmariadb设置开机启动systemctlenablemariadb[root@node1~]#systemctlenablemariadbCreatedsymlinkfrom/etc/systemd/system/multi-user.target.wants/m
Centos7.5 刚安装的mariadb数据库报错报错:ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(usingpassword:NO)原因一:没有启动数据库解决方法:systemctlstartmariadbsystemctlenablemariadb原因二:未知解决方法:[root@db01~]#
基于YUM安装的mariadb多实例.=================================================================1.yum安装mariadb-server包#yuminstallmariadb-server2.创建多实例对应的目录结构#mkdir/mysql/{3306,3307,3308}/{data,etc,socket,log,bin,pid}-pv#tree/mysql//mysql/
一、系统环境[root@localhost~]#cat/etcedhat-releaseCentOSLinuxrelease7.6.1810(Core)二、mysql安装#yuminstallmysqlmysql-servermysql-devel安装mysql-server失败,如下图:[root@localhost~]#yuminstallmysql-serverLoadedplugins:fastestmirrorLoadingm
数据库的选择两大点是:开源和跨平台,满足这三点MySQL、MongoDB和MariaDB。其中MariaDB是MySQL的分支,也是它的进阶产品,未来很有可能替代MySQL。与MySQL相比较,MariaDB更强的地方在于:Maria 存储引擎PBXT存储引擎XtraDB 存储引擎FederatedX 存储引擎更快的复制查询处理线
使用Navicat连接数据库时出现了 HostxxxisnotallowedtoconnecttothisMariaDbserver的情况。发现了是因为授权的问题,使得连接权限受阻。所以,只需要进入数据库中,给予其权限即可。具体解决代码如下:[root@localhost~]#mysql-uroot-pEnterpassword:#首先进入mys
1.临时表当绘画结束时,临时表会自动销毁,无法用showtables查看临时表。MariaDB[jason]>createtemporarytabletmp(prochar(30),citychar(30));QueryOK,0rowsaffected(0.01sec)MariaDB[jason]>insertintotmpvalues('shanghai','shanghai');QueryOK,1
为了看阳光我来到世上数据库介绍数据库是一个存放数据的仓库,目前市面上最流行的数据库大致氛围的两种,一种叫做关系型数据库,一种叫做非关系型数据库,而关系型数据库近期流行的即为mysql,mysql原本是一个开源的数据库后被oracle公司收购,开始进行服务收费,因此,市面上大多数免费
1,Linux上的mysql MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松
启动Mariadb前提需安装mariadb-server-安装mariadb-serveryuminstall-ymariadb-server-启动服务systemctlstartmariadb.service-添加到开机启动systemctlenablemariadb.service-安全设置,以及修改数据库管理员密码mysql_secure_installation-启
1、查看是否安装及可用安装:yumlist|grepmaria2、安装maria(依赖其他几个安装包):yuminstallmariadb-server.x86_64输入'y'继续安装直到安装结束3、检查是否安装:4、安装完后登录提示错误:mysql-uroot-p是由于安装完但是并未启动maria服务5、启动maria有以下几种方法:system
通过yum安装mariadb,并配置MySQL主从服务器主服务器:192.168.10.11从服务器:192.168.10.12#!/bin/bash#====================================================#Author:Mr.Song#CreateDate:2019-02-21#Description:autoconfigMySQLmaster&slave#=====================
实验:实现基于SSL加密的主从复制实验步骤:环境:三台主机,一台CA:200,一台master:150,一台slave:100平时都是在CA上帮用户生成私钥,在服务器上做的1CA,master,slave的证书相关文件mkdir/etc/my.cnf.d/sslcd/etc/my.cnf.d/sslopensslgenrsa2048>cakey.pemopensslreq-new-x509-k
MariaDB[db1]>select*fromstudent;+----+------+-----+--------+-------+|id|name|age|gender|phone|+----+------+-----+--------+-------+|1|a|20|m|119||2|b|20|m|120||3|c|20|m|110
过年了,在老家闲余时间想敲敲代码,发现在安装mariaDb的时候一直报错错误信息:Service‘MySQL’(MySQL)Faildtostart,Verifythatyouhavesuffcientprivilegestostartsystemservices.服务的MySQL(MySQL)启动错误,确认你有权限启动系统服务。记得多年前在使用sqlserver数