mysql过滤器_MYSQL复制过滤器
vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
binlog-do-db=db1? ? ? #白名單模式,僅允許主服務器上生成db1的二進制日志,此選項不支持一行指定多個參數(shù),需要每個參數(shù)寫一行
binlog-do-db=db2
重啟服務
systemctl restart mariadb.service
主服務器上刪除了非db1和db2的一些數(shù)據(jù)庫,發(fā)現(xiàn)這些二進制日志已無法同步到從節(jié)點
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| bdb |
| db2 |
| db3 |
| db5 |
| db6 |
| hellodb |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
9 rows in set (0.001 sec)
MariaDB [(none)]> create database db1;
Query OK, 1 row affected (3.002 sec)
MariaDB [(none)]>
MariaDB [(none)]>
MariaDB [(none)]>
MariaDB [(none)]> drop database bdb;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> drop database db5;
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> drop database db6;
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| db1 |
| db2 |
| db3 |
| hellodb |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
7 rows in set (0.000 sec)
從節(jié)點查看數(shù)據(jù)庫,發(fā)現(xiàn)數(shù)據(jù)庫并未改變,且slave正常
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| bdb |
| db1 |
| db2 |
| db3 |
| db5 |
| db6 |
| hellodb |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
10 rows in set (0.000 sec)
MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.211
Master_User: repluser
Master_Port: 3306
Connect_Retry: 10
Master_Log_File: mariadb-bin.000004
Read_Master_Log_Pos: 487
Relay_Log_File: mariadb-relay-bin.000006
Relay_Log_Pos: 788
Relay_Master_Log_File: mariadb-bin.000004
Slave_IO_Running: Yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#此處顯示狀態(tài)正常
Slave_SQL_Running: Yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#此處顯示狀態(tài)正常
Replicate_Do_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: 487
Relay_Log_Space: 1549
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: 211
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Replicate_Do_Domain_Ids:
Replicate_Ignore_Domain_Ids:
Parallel_Mode: conservative
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Slave_DDL_Groups: 11
Slave_Non_Transactional_Groups: 0
Slave_Transactional_Groups: 0
1 row in set (0.000 sec)
ERROR: No query specified
主服務器上修改db1數(shù)據(jù)庫,增加表格
MariaDB [db1]> create table jinlei (id int,name varchar(20));
Query OK, 0 rows affected (0.004 sec)
從服務器上查看可以同步該庫的表
MariaDB [(none)]> use db1
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [db1]> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| jinlei |
+---------------+
1 row in set (0.000 sec)
主服務器在db3數(shù)據(jù)庫內添加表
MariaDB [db1]> use db3
Database changed
MariaDB [db3]> create table jinlei (id int,name varchar(20));
Query OK, 0 rows affected (0.003 sec)
從服務器無法同步db3數(shù)據(jù)庫內的表
MariaDB [db1]> use db3
Database changed
MariaDB [db3]> show tables;
Empty set (0.000 sec)
總結:在主服務器上配置文件中僅允許記錄db1、db2的二進制文件后,主服務器上修改其他的數(shù)據(jù)庫則無法同步到從服務器,只能在db1或db2上修改數(shù)據(jù)庫才能同步到從服務器。
方法2服務器選項:從服務器SQL_THREAD在relay log中的事件時,僅讀取與特定數(shù)據(jù)庫或特定表相關的事件并應用于本地;
因為二進制日志是在從服務器本地被過濾,二進制日志還是通過主服務器發(fā)送過來了,所以此方法會造成網(wǎng)絡及磁盤I/O的浪費
從服務器上修改系統(tǒng)變量
MariaDB [db3]> stop slave;
Query OK, 0 rows affected (0.002 sec)
MariaDB [db3]> set global replicate_do_db=‘db1,db2‘;
Query OK, 0 rows affected (0.000 sec)
主服務器上在db2中增加一個表
MariaDB [(none)]> use db2
Database changed
MariaDB [db2]> create table jiang (id int,name char(10));
Query OK, 0 rows affected (0.003 sec)
從服務器上db2內可以同步該表
MariaDB [(none)]> use db2;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [db2]> show tables;
+---------------+
| Tables_in_db2 |
+---------------+
| jiang |
+---------------+
1 row in set (0.000 sec)
主服務器在db3中增加一張表
MariaDB [db2]> use db3
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [db3]> create table liang (id int,name char(10));
Query OK, 0 rows affected (0.003 sec)
從服務器上在db3中無法同步該表
MariaDB [db3]> show tables;
+---------------+
| Tables_in_db3 |
+---------------+
| liang |
| mao |
| zheng |
+---------------+
3 rows in set (0.000 sec)
總結:該方法相對于方法一更加的靈活。但這兩種方法都不支持主服務器跨庫操作。
2.
MYSQL復制過濾器
標簽:tables???變量???參數(shù)???har???cond???replica???host???thread???off
本條技術文章來源于互聯(lián)網(wǎng),如果無意侵犯您的權益請點擊此處反饋版權投訴
本文系統(tǒng)來源:https://www.cnblogs.com/jinlei92131/p/13588971.html
總結
以上是生活随笔為你收集整理的mysql过滤器_MYSQL复制过滤器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 埋堆堆app怎么定时关机
- 下一篇: mysql直接执行文件格式_Window