mysql如何在線修改主從復(fù)制選項
前言:
MySQL最常用的架構(gòu)就是主從復(fù)制了,其實主從復(fù)制有很多選項,特別是在從庫端,我們可以設(shè)置復(fù)制過濾,比如說忽略某張表或某個庫。這些過濾選項都是可以在線修改而不用重啟的。原來對這塊了解不多,最近看了下相關(guān)資料,個人覺得這個功能還是很方便的,本篇文章會將這塊內(nèi)容分享給大家。
1.復(fù)制過濾參數(shù)介紹
首先我們要了解設(shè)置復(fù)制過濾的不同參數(shù)。復(fù)制過濾是在從庫端設(shè)置的,可以只復(fù)制某些庫或某些表,也可以忽略復(fù)制某些庫或某些表。這些都是由不同參數(shù)控制的,下面簡單介紹下不同參數(shù)的作用。
- REPLICATE_DO_DB:指定只同步某個庫的數(shù)據(jù)
- REPLICATE_IGNORE_DB:忽略某個庫的同步
- REPLICATE_DO_TABLE:指定同步某個表
- REPLICATE_IGNORE_TABLE:忽略某個表的同步
- REPLICATE_WILD_DO_TABLE:指定同步某些表,可以用通配符
- REPLICATE_WILD_IGNORE_TABLE:忽略某些表的同步,可以用通配符
- REPLICATE_REWRITE_DB:從庫端替換庫名
這些復(fù)制過濾參數(shù)還是很好理解的,只看名字就能大概了解該參數(shù)的作用。默認情況下,這些參數(shù)是都沒有設(shè)置的,開啟主從復(fù)制后從庫端會默認同步全部從主庫發(fā)來的數(shù)據(jù)。
2.修改復(fù)制過濾選項
當(dāng)我們想臨時調(diào)整從庫的復(fù)制策略時,可以設(shè)置上述參數(shù)。我們可以將過濾參數(shù)寫入配置文件然后重啟從庫即可應(yīng)用,但這種方法需要重啟實例,不做推薦。MySQL5.7版本可以進行在線設(shè)置復(fù)制過濾了。但是還是得停復(fù)制,不過不用重啟實例了,方便進行臨時性的調(diào)整。主要用到的是CHANGE REPLICATION FILTER語句,下面就簡單的測試一下:
# 默認未設(shè)置復(fù)制過濾 mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.0.3.16 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: binlog.000004 Read_Master_Log_Pos: 35198 Relay_Log_File: relay-bin.000002 Relay_Log_Pos: 910 Relay_Master_Log_File: binlog.000004 Slave_IO_Running: Yes Slave_SQL_Running: Yes 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: 35198 # 設(shè)置忽略db1庫的復(fù)制 mysql> STOP SLAVE SQL_THREAD; Query OK, 0 rows affected (0.00 sec) mysql> CHANGE REPLICATION FILTER REPLICATE_IGNORE_DB = (db1); Query OK, 0 rows affected (0.00 sec) mysql> START SLAVE SQL_THREAD; Query OK, 0 rows affected (0.01 sec) mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.0.3.16 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: binlog.000004 Read_Master_Log_Pos: 35198 Relay_Log_File: relay-bin.000002 Relay_Log_Pos: 910 Relay_Master_Log_File: binlog.000004 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: db1 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: 35198 # 主庫創(chuàng)建db1測試從庫是否同步 mysql> CREATE DATABASE `db1` DEFAULT CHARACTER SET utf8; Query OK, 1 row affected (0.01 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | db1 | | mysql | | performance_schema | | sys | | testdb | +--------------------+ 6 rows in set (0.00 sec) # 查看從庫狀態(tài) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | testdb | +--------------------+ 5 rows in set (0.00 sec) mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.0.3.16 Master_User: repl Master_Port: 33061 Connect_Retry: 60 Master_Log_File: binlog.000004 Read_Master_Log_Pos: 35383 Relay_Log_File: relay-bin.000002 Relay_Log_Pos: 1095 Relay_Master_Log_File: binlog.000004 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: db1 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: 35383 # 取消復(fù)制過濾參數(shù) mysql> STOP SLAVE SQL_THREAD; Query OK, 0 rows affected (0.01 sec) mysql> CHANGE REPLICATION FILTER REPLICATE_IGNORE_DB = (); Query OK, 0 rows affected (0.00 sec) mysql> START SLAVE SQL_THREAD; Query OK, 0 rows affected (0.01 sec) mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.0.3.16 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: binlog.000004 Read_Master_Log_Pos: 35383 Relay_Log_File: relay-bin.000002 Relay_Log_Pos: 1095 Relay_Master_Log_File: binlog.000004 Slave_IO_Running: Yes Slave_SQL_Running: Yes 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: 35383
上面我們簡單演示了下使用CHANGE REPLICATION FILTER語句在線修改復(fù)制過濾選項的方法,列舉的那些過濾參數(shù)都可以使用該語句修改,不過要注意有些選項是互斥的。應(yīng)該按照實際需求去設(shè)置合適的參數(shù),下面給出官方文檔中的示范語法:
CHANGE REPLICATION FILTER filter[, filter][, ...] filter: REPLICATE_DO_DB = (db_list) | REPLICATE_IGNORE_DB = (db_list) | REPLICATE_DO_TABLE = (tbl_list) | REPLICATE_IGNORE_TABLE = (tbl_list) | REPLICATE_WILD_DO_TABLE = (wild_tbl_list) | REPLICATE_WILD_IGNORE_TABLE = (wild_tbl_list) | REPLICATE_REWRITE_DB = (db_pair_list) db_list: db_name[, db_name][, ...] tbl_list: db_name.table_name[, db_table_name][, ...] wild_tbl_list: 'db_pattern.table_pattern'[, 'db_pattern.table_pattern'][, ...] db_pair_list: (db_pair)[, (db_pair)][, ...] db_pair: from_db, to_db
總結(jié):
本篇文章介紹了如何在線更改復(fù)制過濾選項的方法,不同的過濾參數(shù)有不同的用途,如果你確實有需求要設(shè)置過濾參數(shù),建議一定要進行全面測試,某些參數(shù)設(shè)置后可能影響到其他庫表的復(fù)制。如果想永久生效,可以在線修改后再加入配置文件內(nèi),這樣從庫重啟后還是生效的。
以上就是mysql如何在線修改主從復(fù)制選項的詳細內(nèi)容,更多關(guān)于mysql修改主從復(fù)制的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
mysql觸發(fā)器(Trigger)簡明總結(jié)和使用實例
這篇文章主要介紹了mysql觸發(fā)器(Trigger)簡明總結(jié)和使用實例,需要的朋友可以參考下2014-04-04mysql安裝navicat之后,出現(xiàn)2059,Authentication plugin及本地鏈接虛擬機docker,
這篇文章主要介紹了mysql安裝navicat之后,出現(xiàn)2059,Authentication plugin及本地鏈接虛擬機docker,遠程鏈接服務(wù)器,需要的朋友可以參考下2020-06-06MySQL數(shù)據(jù)庫之聯(lián)合查詢?union
這篇文章主要介紹了MySQL數(shù)據(jù)庫之聯(lián)合查詢?union,聯(lián)合查詢就是將多個查詢結(jié)果的結(jié)果集合并到一起,字段數(shù)不變,多個查詢結(jié)果的記錄數(shù)合并,下文詳細介紹需要的小伙伴可以參考一下2022-06-06MySQL創(chuàng)建和刪除數(shù)據(jù)庫的命令及相關(guān)PHP腳本的操作方法
這篇文章主要介紹了MySQL創(chuàng)建和刪除數(shù)據(jù)庫的命令及相關(guān)PHP腳本的操作方法,這里主要講述Linux中在mysqladmin下的命令操作,需要的朋友可以參考下2015-11-11