最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL binlog_ignore_db 參數(shù)的具體使用

 更新時間:2020年12月07日 15:02:38   作者:MySQL技術(shù)  
這篇文章主要介紹了MySQL binlog_ignore_db 參數(shù)的具體作用,幫助大家更好的理解和使用MySQL數(shù)據(jù)庫,感興趣的朋友可以了解下

前言: 

經(jīng)過前面文章學習,我們知道 binlog 會記錄數(shù)據(jù)庫所有執(zhí)行的 DDL 和 DML 語句(除了數(shù)據(jù)查詢語句select、show等)。注意默認情況下會記錄所有庫的操作,那么如果我們有另類需求,比如說只讓某個庫記錄 binglog 或排除某個庫記錄 binlog ,是否支持此類需求呢?本篇文章我們一起來看下。

1. binlog_do_db 與 binlog_ignore_db

當數(shù)據(jù)庫實例開啟 binlog 時,我們執(zhí)行 show master status 命令,會看到有 Binlog_Do_DB 與 Binlog_Ignore_DB 選項。

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000009 |   282838 |              |                  |                   |
+---------------+----------+--------------+------------------+-------------------+

默認情況下,這兩個選項為空,那么這兩個參數(shù)有何作用?是否如同其字面意思一個只讓某個庫記錄 binglog 一個排除某個庫記錄 binlog 呢?筆者查閱官方文檔,簡單說明下這兩個參數(shù)的作用:

  • binlog_do_db:此參數(shù)表示只記錄指定數(shù)據(jù)庫的二進制日志,默認全部記錄。
  • binlog_ignore_db:此參數(shù)表示不記錄指定的數(shù)據(jù)庫的二進制日志。

這兩個參數(shù)為互斥關(guān)系,一般只選擇其一設(shè)置,只能在啟動命令行中或配置文件中加入。指定多個數(shù)據(jù)庫要分行寫入,舉例如下:

# 指定 db1 db2 記錄binlog
[mysqld]
binlog_do_db = db1
binlog_do_db = db2

# 不讓 db3 db4 記錄binlog
[mysqld]
binlog_ignore_db = db3
binlog_ignore_db = db4

此外,這二者參數(shù)具體作用與否還與 binlog 格式有關(guān)系,在某些情況下 binlog 格式設(shè)置為 STATEMENT 或 ROW 會有不同的效果。在實際應(yīng)用中 binlog_ignore_db 用途更廣泛些,比如說某個庫的數(shù)據(jù)不太重要,為了減輕服務(wù)器寫入壓力,我們可能不讓該庫記錄 binlog 。網(wǎng)上也有文章說設(shè)置 binlog_ignore_db 會導致從庫同步錯誤,那么設(shè)置該參數(shù)到底有什么效果呢,下面我們來具體實驗下。

2. binlog_ignore_db 具體效果

首先說明下,我的測試數(shù)據(jù)庫實例是 5.7.23 社區(qū)版本,共有 testdb、logdb 兩個業(yè)務(wù)庫,我們設(shè)置 logdb 不記錄 binlog ,下面來具體實驗下:

# binlog 為 ROW 格式 

# 1.不使用 use db
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |      154 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
mysql> select database();
+------------+
| database() |
+------------+
| NULL       |
+------------+
1 row in set (0.00 sec)
mysql> CREATE TABLE testdb.`test_tb1` ( id int , name varchar(30) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.06 sec)

mysql> insert into testdb.test_tb1 values (1001,'sdfde');
Query OK, 1 row affected (0.01 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |      653 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> CREATE TABLE logdb.`log_tb1` ( id int , name varchar(30) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.05 sec)

mysql> insert into logdb.log_tb1 values (1001,'sdfde');
Query OK, 1 row affected (0.00 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |      883 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
mysql> insert into logdb.log_tb1 values (1002,'sdsdfde'); 
Query OK, 1 row affected (0.01 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |      883 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+

mysql> alter table logdb.log_tb1 add column c3 varchar(20);   
Query OK, 0 rows affected (0.12 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     1070 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
# 結(jié)論:其他庫記錄正常 logdb庫會記錄DDL 不記錄DML

# 2.使用 use testdb跨庫
mysql> use testdb;
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
mysql> select database();
+------------+
| database() |
+------------+
| testdb     |
+------------+
1 row in set (0.00 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     1070 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> CREATE TABLE `test_tb2` ( id int , name varchar(30) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.05 sec)

mysql> insert into test_tb2 values (1001,'sdfde');
Query OK, 1 row affected (0.04 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     1574 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> CREATE TABLE logdb.`log_tb2` ( id int , name varchar(30) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.05 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     1810 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> insert into logdb.log_tb2 values (1001,'sdfde');
Query OK, 1 row affected (0.01 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     1810 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
# 結(jié)論:同樣logdb庫會記錄DDL 不記錄DML 

# 3.使用 use logdb跨庫
mysql> use logdb;
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
mysql> select database();
+------------+
| database() |
+------------+
| logdb      |
+------------+
1 row in set (0.00 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     1810 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> CREATE TABLE testdb.`test_tb3` ( id int , name varchar(30) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.23 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     1810 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> insert into testdb.test_tb3 values (1001,'sdfde');
Query OK, 1 row affected (0.02 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     2081 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> CREATE TABLE `log_tb3` ( id int , name varchar(30) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.05 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     2081 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> insert into log_tb3 values (1001,'sdfde');
Query OK, 1 row affected (0.02 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     2081 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
# 結(jié)論:logdb都不記錄 同時不記錄其他庫的DDL

# 4.每次操作都進入此庫 不跨庫
mysql> use testdb;
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
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     2081 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> CREATE TABLE `test_tb4` ( id int , name varchar(30) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.05 sec)

mysql> insert into test_tb4 values (1001,'sdfde');
Query OK, 1 row affected (0.01 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     2585 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> use logdb;
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
mysql> CREATE TABLE `log_tb4` ( id int , name varchar(30) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.04 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     2585 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> insert into log_tb4 values (1001,'sdfde');
Query OK, 1 row affected (0.01 sec)

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000011 |     2585 |              | logdb            |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
# 結(jié)論:其他庫全部記錄 logdb全不記錄

同樣的,將 binlog 格式設(shè)置為 STATEMENT ,再次進行測試,這里不再贅述測試過程,總結(jié)下 STATEMENT 格式下的實驗結(jié)果:

  • 未選擇任何數(shù)據(jù)庫進行操作,所有都會記錄。
  • 選擇testdb,對testdb和logdb分別進行操作,所有庫都會記錄。
  • 選擇logdb,對testdb和logdb分別進行操作,所有庫都不會記錄。
  • 選擇某個庫并只對當前庫進行操作,則記錄正常,不會記錄logdb。

看了這么多實驗數(shù)據(jù),你是否眼花繚亂了呢,下面我們以思維導圖的形式總結(jié)如下:

這么看來 binlog_ignore_db 參數(shù)的效果確實和諸多因素有關(guān),特別是有從庫的情況下,主庫要特別小心使用此參數(shù),很容易產(chǎn)生主從同步錯誤。不過,按照嚴格標準只對當前數(shù)據(jù)庫進行操作,則不會產(chǎn)生問題。這也告訴我們要嚴格按照標準來,只賦予業(yè)務(wù)賬號某個單庫的權(quán)限,也能避免各種問題發(fā)生。

總結(jié): 

不清楚各位讀者是否對這種介紹參數(shù)的文章感興趣呢?可能這些是數(shù)據(jù)庫運維人員比較關(guān)注的吧。本篇文章主要介紹關(guān)于 binlog 的 binlog_ignore_db 參數(shù)的具體作用,可能本篇文章實驗環(huán)境還不夠考慮周全,有興趣的同學可以參考下官方文檔,有助于對該參數(shù)有更深入的了解。

以上就是MySQL binlog參數(shù)的使用的詳細內(nèi)容,更多關(guān)于MySQL binlog參數(shù)的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

乌海市| 原平市| 惠安县| 江门市| 武强县| 定兴县| 陆川县| 丹江口市| 五家渠市| 莒南县| 卢氏县| 邢台市| 皋兰县| 十堰市| 陇西县| 汤原县| 开原市| 凯里市| 建阳市| 江华| 明溪县| 舟曲县| 昌图县| 邢台县| 平谷区| 德江县| 灵川县| 潞城市| 宿迁市| 会理县| 榆林市| 广河县| 凤山县| 济阳县| 宝坻区| 九江县| 阜宁县| 镇远县| 塔河县| 当阳市| 沙坪坝区|