日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

MYSQL 5.7 主从复制 -----GTID说明与限制 原创

發(fā)布時間:2025/6/17 数据库 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MYSQL 5.7 主从复制 -----GTID说明与限制 原创 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

http://www.cnblogs.com/cenalulu/p/4309009.html

http://txcdb.org/2016/03/%E7%B3%BB%E7%BB%9F%E8%A1%A8-mysql-gtid_executed ??騰訊CDB團隊

http://mysqllover.com/?p=594&utm_source=tuicool&utm_medium=referral

http://blog.itpub.net/29733787/viewspace-1462550/

http://blog.csdn.net/thundermeng/article/details/50401150

master:
GTID:
[my.cnf]
server-id=xx
master_info_repository = TABLE relay_log_info_repository = TABLE log_bin = bin.log sync_binlog = 1 gtid_mode = on enforce_gtid_consistency = 1 log_slave_updates binlog_format = row relay_log = relay.log relay_log_recovery = 1 binlog_gtid_simple_recovery = 1

slave:
[my.cnf] master_info_repository = TABLE relay_log_info_repository = TABLE log_bin = bin.log sync_binlog = 1 gtid_mode = on enforce_gtid_consistency = 1 log_slave_updates binlog_format = row relay_log = relay.log relay_log_recovery = 1 binlog_gtid_simple_recovery = 1
skip-slave-updates

//Log-slave-update該參數(shù)在搭建master=>slave=>slave的架構時,需要配置。

GTID 變量:

GTID_PURGED:已經(jīng)被刪除的binlog的事務,它是GTID_EXECUTED的子集 //從上面就表現(xiàn)為已經(jīng)執(zhí)行了GTID_OWNED: 表示正在執(zhí)行的事務的gtid以及對應的線程ID。GTID_EXECUTED 表示已經(jīng)在該實例上執(zhí)行過的事務; 執(zhí)行RESET MASTER 會將該變量置空; 我們還可以通過設置GTID_NEXT執(zhí)行一個空事務,來影響GTID_EXECUTEDGTID_NEXT是SESSION級別變量,表示下一個將被使用的GTID

?

RESET MASTER: 刪所有的binary log文件 Deletes all binary log files listed in the index file, resets the binary log index file to be empty, and creates a new binary log file.清空gtid_purged與gtid_executed 設為empty string RESET MASTER also clears the values of the gtid_purged system variable as well as the global value of the gtid_executed system variable (but not its session value); that is, executing this statement sets each of these values to an empty string (''). In MySQL 5.7.5 and later, this statement also clears the mysql.gtid_executed table (see mysql.gtid_executed Table).This statement is intended to be used only when the master is started for the first time.ImportantRESET MASTER與PURGE BINARY LOGS不同之處 The effects of RESET MASTER differ from those of PURGE BINARY LOGS in 2 key ways:RESET MASTER removes all binary log files that are listed in the index file, leaving only a single, empty binary log file with a numeric suffix of .000001, whereas the numbering is not reset by PURGE BINARY LOGS.reset master 用在 復制狀態(tài)為停止時,運行是不支持的,PURGE BINARY LOGS不受影響 RESET MASTER is not intended to be used while any replication slaves are running. The behavior of RESET MASTER when used while slaves are running is undefined (and thus unsupported), whereas PURGE BINARY LOGS may be safely used while replication slaves are running.

?

RESET SLAVE makes the slave forget its replication position in the master's binary log.
This statement is meant to be used for a clean start:

It clears the master info and relay log info repositories, //刪除master info and relay log info,如使用start slave 會重建文件,內(nèi)容:slave IO,SQL 線程相關信息
deletes all the relay log files, and starts a new relay log file. //delete all the relay log files
It also resets to 0 the replication delay specified with the MASTER_DELAY option to CHANGE MASTER TO.
To use RESET SLAVE, the slave replication threads must be stopped (use STOP SLAVE if necessary). //要求replication threads 停止Note All relay log files are deleted, even if they have not been completely executed by the slave SQL thread. //所有的中繼日志被刪
(This is a condition likely to exist on a replication slave if you have issued a STOP SLAVE statement or if the slave is highly loaded.)RESET SLAVE does not change any replication connection parameters such as master host, master port, master user, or master password, which are retained in memory. This means that START SLAVE can be issued without requiring a CHANGE MASTER TO statement following RESET SLAVE.
RESET SLAVE ALL //能夠把所有的連接參數(shù)清除,而RESET SLAVE 不刪
Connection parameters are reset by RESET SLAVE ALL.
(RESET SLAVE followed by a restart of the slave mysqld also does this.)

?

  

bin-log相關配制:

Binlog_format:STATEMENT|ROW|MIXED

參數(shù)也特別重要。從mysql5.1版本開始引入這個參數(shù),該參數(shù)可以設置的值有STATEMENT\、ROW、MIXED

(1)STATEMENT格式和之前的mysql版本一樣,二進制日志文件記錄的是日志的邏輯失SQL語句。

(2)在ROW格式下,二進制日志記錄的不再是簡單的SQL語句了,而是記錄表的行更改情況,此時可以將InnoDB的事務隔離基本設為READ?COMMITTED,以獲得更好的并發(fā)性。

(3)MIXED格式下,mysql默認采用的STATEMENT格式進行二進制日志文件的記錄,但是在一些情況下會使用ROW格式,可能的情況包括:


set session sql_log_bin=0/1 :可以會話級別控制SQL操作記錄到BINLOG 中
max_binlog_size:單個文件最大大小,超過就切換
Binlog_cache_size:binlog:緩存大小 (線程級別的分配)

binlog 刪除:
1.手動清理
1.purge{binary|master} logs to "bin-file-name"
purge{binary|master} logs before "datatime-expr"
2.停止mysql
rm命令清除 binlog
修改INDEX

2.自動清理
expire_logs_days=N (1<=n<=99):二進制日志存放天數(shù)


sync_binlog=[N]
表示每寫緩存多少次就同步到磁盤,如果將N設置為1

則表示采用同步寫磁盤的方式來寫二進制日志
,該參數(shù)很重要,這個以后還會提到。
值得注意的是,在將該參數(shù)設置為
1時,也應該將innodb_support_xa設為1來解決,
這可以確保二進制日志和
InnoDB存儲引擎數(shù)據(jù)文件的同步。






中繼日志:
flush logs:切換中繼日志
relay_log_purge=0/1 是否自動刪除 MHA中為0
max_relay_log_size 定義文件大小


mysql> show master status; //當前工作LOG文件 +------------+----------+--------------+------------------+-------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------+----------+--------------+------------------+-------------------------------------------+ | log.000003 | 194 | | | 191f7a9f-ffa2-11e5-a825-00163e00242a:1-10 | +------------+----------+--------------+------------------+-------------------------------------------+ 1 row in set (0.00 sec)mysql> flush logs; //切換日志文件 Query OK, 0 rows affected (0.05 sec)mysql> show master status; +------------+----------+--------------+------------------+-------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------+----------+--------------+------------------+-------------------------------------------+ | log.000004 | 194 | | | 191f7a9f-ffa2-11e5-a825-00163e00242a:1-10 | +------------+----------+--------------+------------------+-------------------------------------------+ 1 row in set (0.00 sec)

master 上的狀態(tài):


purge binlogs in 'log.000002'; slave上:
change master to master_host='10.24.220.232',master_user='repl',master_password='123',master_port=3306,master_auto_position=1;

reset master:對gtid_executed與gtid_purged初始化為空字符串
set global gtid_purged才可用

?

OK 強制同步成功接收到GTID集,

但(9,10)執(zhí)行是不功的

?

?

?

?

?

?

?

?

?

?

slave上:

轉載于:https://www.cnblogs.com/zengkefu/p/5478442.html

《新程序員》:云原生和全面數(shù)字化實踐50位技術專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的MYSQL 5.7 主从复制 -----GTID说明与限制 原创的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。